Question d’entretien chez 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.

Réponse à la question d'entretien

Utilisateur anonyme

24 juil. 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