Amazon Interview Question for Software Engineer / Developers






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

something like heapsort or what?

- arpit June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

use preorder traversal ,store in array and print the array finally.

- vineel January 21, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

BST?

- AL June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its Heap sort

- Raghav June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that they are looking for in-order as opposed to post-order. Something like this:

void printInOrder(Nameval *nvp) {
if (nvp == NULL) return;
printInOrder(nvp->left);
printf("nvp = %p, name = %s, val = %d\n", nvp, nvp->name, nvp->val);
printInOrder(nvp->right);
}

- Senile Sam June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think inorder will give sorted result only for BST. the question is for a Binary tree though

- Anonymous June 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Inorder traversal sequence (left, root, right); this produces a sorted sequence

- rsl June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

As mentioned above its a binary tree not a BST.

- King@Work June 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

any thing better then heap sort guys?

- baghel June 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Convert BT in to singly or doubly Linked list it will take O(N) time & O(1) Time
sort linked list it will take O(nlogn) time & O(1) space & coding this is not typical task...:)

Correct me if i am wrong

Shashank

- WgpShashank June 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

heapsort would take O(nlogn) in even worst case but if you make it a list and use some other sorting methods (eg quick sort) it will fetch you o(n^2) in worst case so you cant say o(nlogn) with certainty for your solution.

- someone June 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe just traverse the whole tree, put them into array and sort them.

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

even if this is bst.how to do heapsort on bst? i mean we need indexes for heapify function.isn't it?

- baghel June 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

convert Binary Tree to BST -> do inorder traversal.
better than creating a heap i guess

complexity O(n log(n)) depends on how balance your BST is though.

- codemonkey June 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is probably the best answer

- Arie June 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is probably the best answer

- Arie June 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rearrange nodes to form a heap . O(n)
Delete min - O(nlogn)
So complexity O(nLogn)

- Curious June 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Cant we do this?

Traverse through the binary tree and add each of the nodes to a Heap.
Print the Heap and it does it automatically in sorted order..

Does this idea work?

- vind June 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Oops.. sorry I meant Hash and not Heap..
but this will not work if there are nodes with a same value..

- vind June 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the question needs simply understand the binary tree

void printbinarytree
(
struct treenode * root
)
{
if (root)
{
printbinarytree(root->leftchild);
printf("%s\n", root->name);
printbinarytree(root->rightchild);
}
}

- GhostArcher September 23, 2011 | 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