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.
The answer would be a combination of using a hash and min_heap.
First we count how many times each items is repeated in array and store them in hash. Then, based on the frequency of each item generate a min_heap.
However, to make it easier to return the result, we can store a pair value in heap <freq,actual#>.
For example for the given input {1,2,3,2,1,2,1,2,3}, we store the following pairs in min_heap structure:
<2,3>, <3,1>, <4,2>
Then while making the min_heap we make sure to delete the root of tree if the size of heap reaches the value of queue.
In this case we only keep track of k most frequent values in array in min_heap, while the root of tree is the answer.
Here is C++ code implementation using STL:
- ashkanxy November 11, 2018