Microsoft Interview Question
Software Engineer / Developerslet the lengths of the two arrays be m and n and m<n
create a hashmap from the smaller array --> O(m).
For every element in the larger array check if the element exists in the hashmap. if it does then push into a vector --> O(n)
Time Complexity: O(m) + O(n) ==> O(n) {since m<n}
Space Complexity: O(m) + O(m) ==> O(m)
1) Create an array of size 256 and of type int to hold all ASCII values.
2) Initialize the whole array to 0
3) Iterate through the first array and set the respected index in array according to their ASCII values to 1.
4) Iterate through the second array and check which elements have 1 in the array according to their ASCII.
Time complexity:
O(256) + O(m) + O(n) = O(n)
1)Form a BST using first Array...
- keshav January 24, 20112)Now for each element in 2nd array...search for correponding element in BST....
3)if that element is present delete it and continue for the whole array....