Amazon Interview Question for SDE1s


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

Either max heap or min heap. It depends on your available memory, because max heap has to store all elements while min heap just store k elements. Also they have different time complexity. Choose either solution depending on your needs.

- Yue March 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hey why do we need to store all elements for max heap we could just store the top k elemts and every time a new number comes we need to check the leaves i am sure min heap would be better but please tell me why we need to store all elemenst for max heap

- anony March 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The max heap is supposed to be built with the search count as the value, the highest search count element will make the root element in the heap. I could not get the significance of using a min heap. Can you please explain if i am missing anything.

- sam April 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Create a max heap of K elements. Every heap node will represent the counter value of the search count.

- sam March 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Build k max heap will work.
Every time a new element comes add it to k max heap if required.
K max heap will maintain K largest element at a give time.

- Krishna K Tiwari March 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think this will work, the heap could be very big, but at any given time it will be accurate.
So each node has the number of times an element is searched for, as the key. Every time a data element comes in the corresponding node is incremented and the heap nodes with highest number of searches is always at the top and is continually updated.

- pm March 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

I think you need min-heap. Every time you get an element in the stream, compare it against the top of the heap. If current is larger than the top, remove the top and insert the current, else discard the current.

- manish.baj March 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is right. If you need the max k, then you use a min-heap, and restrict yourself to O(k) space and O(k log k) time.

By using a max-heap, you will have to insert all elements and this will essentially be same as heap sort.

- Loler March 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am little bit confused...
does the data stream contains tuples (string, noOfTimesSearched) or just strings one after another?

- sapy April 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am little bit confused...
does the data stream contain tuples (string, noOfTimesSearched) or just strings one after another?

- sapy April 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Before we use the heap, do we need to preprocess the strings? Do we need a hash table to store the number of times of a corresponding item that appears?

- Tobias April 01, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More