amit deol
BAN USER I am self motivated person and I have fresh mind to work in any environment .
I need platform to improve my skills and knowledge also I am eager in learning new things.
we Can use removeall method provided by java.
we have to build two arraylist one for the Input words and second for the words to be removed and then simply use
arrList1.removeAll(arrList2);
now arrList1 will have the required output just print the result.
It will give the same time complexity as mentioned in above examples.
public class QuickSort {
public static void quickSort(int[] arr, int start, int end) { //-- 1
if (start >= 0 && end < arr.length && start < end) { //--- 1
int pivot = arr[start]; //--1
swap(arr, start, end); //-- 3
int left = start, right = end-1; //---1
while (left < right) { Best Case 1 Worst case N
while (left < arr.length && arr[left] < pivot ) left++; //-- N*N
//-- OR
while (right >= 0 && arr[right] > pivot) right; //-- N*N
if (left < right) swap(arr, left++, right); //--Best Case 0 Worst case N*N
}
if (arr[left] > pivot) swap(arr, left, end); 1 or 3*N
quickSort(arr, start, left-1); M/2*M/2
quickSort(arr, left+1, end); M/2*M/2
}
}
private static void swap(int[] arr, int p, int q) {
int tmp = arr[q]; //--- 1
arr[q] = arr[p]; //--- 1
arr[p] = tmp; //--- 1
}
}
so time complexity= will be the come of all and take the worst case in consideration it will be (Constant Time) C+N+N2+N2+N~N2
time complexity= =O(N2)
space Complexity =2N ~ O(N)
You need not to use contains as purpose of contains can be fulfilled by add operation as it will return false for duplicates and interviewer is only asking for printing the duplicates so you need not to store the duplicates in another hashset( assuming that we need not to worry about the duplicates of duplicates here.)
- amit deol February 17, 2014n is the number of telephone calls allowed for a lumpsum charge of rs.300.
r is the rate beyond that.
You would get equations like the following.
2n+125/r+625/r=1400
2nr+ 125+625 = 1400r
2nr + 750-1400r=0 --1
(1400-n)r=1250
1400r -nr -1250 =0 --2
now multiply 2 by 2 and add both 1 nd 2
1400r - 1750 =0
r = 1750/1400 = 1.25
so n = 400
@Manisha your method will give a time complexity of O(n.log(n)).
- amit deol February 20, 2014but if we use radix sort as we know the range of inputs(letters OR int or both) so it will give a linear time complexity.