Google Interview Question

Get the two highest number in a binary search tree

Interview Answers

Anonymous

Jul 2, 2012

go right until possible -> this is the biggest element. if the biggest element has a left child, find the most right element in the subtree of this left child (might be itself) else the parent of the biggest element is the 2nd biggest

8

Anonymous

Mar 20, 2015

Can i type

Anonymous

Mar 20, 2015

F's case will not work in this instance 5 1 4 Do a reverse inorder Traversal saving the two biggest and quit when you find them. reverseBSTTraverse(node, [], 2) def reverseBSTTraverse(node, array=[], k=2): if len(array) == k: print array return if node == None: return reverseBSTTraverse(node.right, array , k) array.append( node.value ) reverseBSTTraverse(node.left, array, k )