Amazon Interview Question for SDE-3s

Country: United States
Interview Type: In-Person

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

If it is a binary search tree, you could do in-order with going to right first and then to left.
This will make in-order traverse in descending order and stop traversal at count = 3.

If this is not a binary search tree, then convert the tree to a max heap - should be O(n) I believe. then pop three times to get the third highest.

- Sunny August 31, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

Keep an array of 3 elements. Initialized to Integer.minimum.

Traverse the BT (inorder) and push the elements in to a position it fits in the 3 element array/linked list(sorted) and remove the last element. After the whole traversal is complete then take the last index in the array..... simple.

This way you can solve for any order - of course it taxes memory a bit.

- mahesh sankaran September 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

in a BST or a BT? in BST, go to highest node and go back two. : O(lg(n)) if tree is balanced
in BT just scan all element using some traversal (in order, post order, ...) and keep an array with the three highest numbers O(n)

- Chris August 31, 2017 | Flag Reply

Add a Comment

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


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


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