Google Interview Question

Given a node in a binary tree find the next greatest value in the entire node.

Interview Answers

Anonymous

Feb 24, 2012

I guess it is a binary search tree? And does each node have a parent pointer?

Anonymous

Mar 6, 2012

for BST : get the node and find the inorder successor if(n->right) : find minimum in n->right else find parent of n in loop, till n is parent->right : (n = parent, find parent(n)