Amazon Interview Question for SDE1s


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
5
of 7 vote

1. create a file reader for each file
2. create Min Heap and put first number from each file.
3. delete min from Min Heap. if the deleted element is from file 'X' then read next element from file 'X' only
4. repeat step 3 for 1 million times.

- Sniga June 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Take 2 files in memory, pick the top 1 million entries from it (just like we do for merge sort) and store them in a 3rd file. Name this third file as 'X'.
2) Take one more file from disk, and X, and together follow the same step as in step 1).

Essentially, in each pass, we are getting the best 1 million of the two files involved for comparison.

Note: This is a naive solution. Thinking for better ones.

- Learner June 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The condition is strong 10 files each has 10 million SORTED number. I will use merge sort.
3 million in memory to use: one million left for the sorted number; then 2 million cut into 10 sections, each has 0.2 million. Keep ten pointers to each of them. Get the values of the pointers pointing to and get the smallest, put into the "sorted" area. Read a new integer from the file which is related to the selected section and update the value the pointer pointed to and increase the pointer by 1. (For all pointers, it can not be more than 1 million: pointer % 0.2 million). For each value need no more than 9 comparison. Overall efficiency O(n).

- Anonymous June 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

LSD Radix Sort would be the best

- HVT June 10, 2014 | 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