Amazon.com Interview Question
1,572 Interview Reviews |
Back to all Amazon.com Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Development Engineer Intern at Amazon.com:
Print the BST in level order
See more for this Amazon.com Software Development Engineer Intern Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
0 of 3 people found this helpful
bstprint(node, count) {
if (node == null) {
return;
}
print count + ": " + node.value; //pseudocode for printing cause lazy
bstprint(node.left, count + 1);
bstprint(node.right, count + 1);
}
bstprint(root, 0); //initial call
Helpful Answer?
Yes |
No
Inappropriate?
return
nodes=collections.deque([tree])
currentCount, nextCount = 1, 0
while len(nodes)!=0:
currentNode=nodes.popleft()
currentCount-=1
print currentNode.val,
if currentNode.left:
nodes.append(currentNode.left)
nextCount+=1
if currentNode.right:
nodes.append(currentNode.right)
nextCount+=1
if currentCount==0:
#finished printing current level
print '\n',
currentCount, nextCount = nextCount, currentCount
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Anonymous: