Amazon Interview Question for SDE1s


Country: India
Interview Type: In-Person




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

We can use tries here instead of BST

- Brandy May 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Take one element from file and build a priority queue. Take the least element each time and revamp the PQ from the respective file which was removed.

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

Since the Files are already sorted. All you have to do is a external merge till you get 1 million elements. You don't need any more items from the Files.

- Abhi May 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a BST with words from the Files. Each Node in the tree will have below structure

Node{
String word;
String[] fileName;
int count
int[] line
}

For each word increment the count and insert the File name and line# in node structure

Once you are done creating the tree. Remove all Nodes that have count as 1.

- Abhi May 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take first one million integer and merge it with next file which will be total 2 million records and now sort it which will be nLog(N) less than 3 million .

Now pick the 1 million records from here and merge with the next file and repeat the process. At last you will have the 1 million sorted records.

- ur.devesh May 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why sort? Assuming a 3 million buffer (which is not optimal for merging due to shifts) once u merge 1 million from 1 and 2 u have smallest 1 million. Take those and merge with 1million from 3 and so on. No sorting is required no?

- Noobie May 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a max heap of first 1million integers from file 1.

Now keep reading the integers from file 2- file 10.

If the integer read is smaller than the maximum element of the max heap, delete the maximum element from the heap, heapify then and insert this new element.

- Darklord May 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since accessing files for each number is expensive, and since we have enough memory to hold 3 million, maintain arrays for each file in memory.

Fill the arrays with numbers from corresponding files until memory limit is reached (almost).

Now maintain a min-heap of 10 numbers (10 is number of files) and output the smallest number. Move the index in corresponding array from where the smallest number was sourced. Add the next element in this array to the heap. Continue this process until 1 million smallest numbers were found in sorted order.

When any one file array in memory goes empty, refill the array with numbers from corresponding file.

- lowsloper May 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please correct me if I am wrong.
Steps:

1) You make a file list array with all file names.
2) Process one by one.
3) for each file:
Find a word and store the word and its corresponding line number and file name in a Key Value store.
A Hashmap of type <String, String[]>
String=word in the file.

String[0]= Count of word occurence
String[1]= Line Number
String[2]=Latest File name where the word appears (this is to handle the case where a single word appears in different files)

Each time a word appears increment count and update the line number and file name(if different)

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

B-tree since it's file based storage

- aks June 13, 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