is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
We can use partition algorithm from quick sort to reduce the time complexity. Hashing is okay, but we can do this in O(1) space with a decent time complexity.
- viscrisn August 26, 2014> Partition the array using max. Now all the elements to the left of this array is smaller than this. Now partition using min. So we have min and max at its sorted position. All the numbers between min and max are also in between position of max and min in the array.
//O(n)
Eg: {3, 4, 2, 6, 8, 9}, max = 8, min = 4
-> {3, 2, 4, 6, 8, 9}
> Sort only between max and min. So here time complexity is O(klogk) where k is number of elements between max and min. Also we know that k is strictly < n else there would be no answer.
> From now on, our array means only the element between min and max.
> randRange = (max - min +1) - size(array)
> random = Math.rand( )%randRange;
> So now you have a number between 0 and number of missing elements.
You can just run binary search and return the missing number depending on the position.
Suppose random returned 2 in above array, we just find the number which has 2 numbers lesser in its position using binary search and print that. //O(logk)
So overall time complexity would be O(klogk) where k is the number of elements between max and min array elements. It does not depend upon range of max and min.
Space complexity O(1).