Amazon |SD2| Virtual Onsite | Find the Lowest Common Ancestor in a Binary tree
Anonymous User
1102

I have been asked this question for the Amzon SD2 (UK) position, I wasn't able to come up with a working solution and as obvious the result was rejection. Unlike other LCA question in leetcode, this one is given with the indexes of the nodes and need to find the index of the common ancestor node.

Question:
Find the first (lowest) common ancestor of two nodes in a binary tree without allocating any tree data structure in memory.

The first common ancestor of two nodes v and w is the lowest (i.e. deepest) node that has both v and w as descendants.

Consider the binary tree's indexes starting from 1 in the root, increasing from the leftmost node to the right at each level. (Standard tree node indexing from left to right)

public  int findLCA(int index1, int index2) {
//returns the index of the common ancestor
}
Comments (6)