Google Interview Question: Given a node in a binary tree... | Glassdoor

Interview Question

Software Developer Interview

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

  in the entire node.

Interview Answer

2 Answers


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

Anonymous on Feb 24, 2012

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

aranjany on Mar 5, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.