Amazon Amazon Interview Question for Software Engineer / Developers


Country: United States




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

I guess the problem statement is to create Huffman code for the string "AAAAAABBCCDDEEFFFFF"

Solution: <Well known method, just adding for the completeness sake>
1. Find the list of all the symbols and their respective frequencies.
A 6, B 2, C 2, D 2, E2 , F 5.
2. Aim is to create a binary tree so that A, B, C, D, E, F are leaf nodes. Code for any leaf node would be path from the root in terms of Left of Right turn you take on every node from the root. Lets denote 0 for left and 1 for right. Hence for the example root -> lc->rc->lc->leafnode, code for leaf node is 010.
Now Huffman code dictates that the symbol with the maximum frequency should have smallest code. Hence the binary tree we would like to create should be such that A with maximum frequency should have min length of code.
3. How do we do it?
a. Store all the leaf nodes in a min heap.
b. Delete two nodes from the heap.
c. Create a binary tree from the two nodes such that rootNode.freq = leafNode1.freq + leafNode2.freq;
d. Add that rootNode to the min heap.
<Continue this process till we have only one element and the resultant tree would be something similar to what is being asked.>

- SR February 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi, once BC and DE is grouped, we have BC(4), DE(4), F(5), A(6) in min heap. So, when we extract two we should group BC and DE together in next step, shouldn't ?

- Deepak February 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

I would give this question a failing grade

- gen-y-s January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is not clear to me how you found the string ADEBCF from AAAAAABBCCDDEEFFFFF.
Can you please explain?

- MarcoF January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please re-write the problem with clear example.

- Raj January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yea, I believe the output of the Huffman encoding should be a string of 0's & 1's or L's & R's to indicate the path from the root to the respective letters, such that the length is minimal with respect to the given string, the constructed frequency table, and, of course, the Huffman tree, as depicted.

- evandrix January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For example:
ABCDDEF(19) ------ BCDEF(13) -------- BCDE(8) ------ CDE(6) ----- DE(4) ----- E(2)
| | | | | |
A(6) F(5) B(2) C(2) D(2) E(2)

Codes: A - 10, F - 110, B - 1110, C - 11110, D - 111110, E - 1111110

- Alex January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

it seems this is related to trie data structure

- alien February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is not. Try creating a trie structure for the given string. Huffman coding is an encoding method. It creates code for each symbol so that the symbol with maximum frequency gets the smallest code.

- SR February 09, 2013 | Flag


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