Monthly Archives: October 2016

3Sum –>LeetCode

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.   For example, … Continue reading

Posted in Uncategorized | Leave a comment

Regular Expression Matching

From Leet Code: ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p) Some … Continue reading

Posted in Uncategorized | Leave a comment

Collections in Java

@Test public void testCollections() { LinkedList<Integer>list=new LinkedList<Integer>(); list.add(10); list.addFirst(5); list.addLast(20); System.out.println(“Contents of Linkedlist are”); for(int i:list) { System.out.println(i); } TreeSet<Integer> set=new TreeSet<Integer>(); set.add(10); set.add(20); Iterator itr=set.iterator(); System.out.println(“Contents of Set are”); while(itr.hasNext()) { System.out.println(; } Stack<Integer> stack=new Stack<Integer>(); stack.push(10); stack.push(20); System.out.println(“Contents … Continue reading

Posted in Uncategorized | Leave a comment

Remove whitespaces in a String-Java

@Test public void testRemoveWhiteSpaces() { String input=”Whitespaces should be replaced”; System.out.println(input.replaceAll(“\\s+”, “”)); }

Posted in Uncategorized | Leave a comment


import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.testng.annotations.Test; public class WordCountTest { @Test public void testWordCount() { String input=”Ashish is a good boy and he is good in coding”; String[] words = input.split(“\\s+”); HashMap<String,Integer> hm=new HashMap<String,Integer>(); for(String s:words) { if(hm.containsKey(s)) … Continue reading

Posted in Uncategorized | Leave a comment

Finger Command

Finger command displays information about users on a given host/system. $finger Displays all logged in users on a system. $finger Check all logged in users on remote machine.  

Posted in Shell Script, Uncategorized | Leave a comment

Insertion Sort-Java

package tests; import org.testng.annotations.Test; public class InsertionSortTest { public void sort() { int []values={10,2,8,19,6}; insertionSort(values); System.out.println(“———————-Insertion Sort——————————–“); for(int i:values) { System.out.println(i); } } public int [] insertionSort(int []values) { int temp; for(int i=1;i<values.length;i++) { for(int j=i;j>0;j–) { if(values[j] < values[j-1]) … Continue reading

Posted in Uncategorized | Leave a comment