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.
Assuming that there is an infinite stream of numbers and your are supposed to tell the k most occurring numbers, I am giving you an approach.
- Sanyam Jain May 04, 20141. Maintain a Linked List with decreasing order of frequency. Each node of linked list will have the number and its frequency.
2. Maintain a hash map with key as number and value as the pointer to the node in the linked list.
3. If a new number comes, add it to the tail of the linked list, maintaing the hash map.
The cost of maintaining the list for every number is O(1).
Reason:
1. When the list is empty - add a node O(1)
2. When node is not in list - add a node O(1)
3. when frequency of a node changes, it moves before the previous node - O(1)
The cost of returning the top occurred (k) numbers - O(k) - returning the first k numbers from the linked list.