Frage im Vorstellungsgespräch bei Google

For a n-node tree, you are given a left leaf node pointer and right leaf node pointer. Write a function to find the number of nodes between the leaves pointed by the left and the right pointer.

Antwort im Vorstellungsgespräch

Anonym

24. Juli 2010

Find the first common ancestor(fca) of both nodes. From the fca->right chlid-> left child make a tree traversal and count the number of nodes From the fca->left child -> right child make a tree traversal and count the number of nodes