Interview Question
Country: United States
Since you didn't mention anything, I will assume its a general tree. In that case, one of the ways is the following.
1. Print out the path from root to each node.
2. Find the common substring to this path.
3. The last node is the least common ancestor.
There are various implementations to this method including Dynamic Programming. (Due to no link restriction, I can't give a relevant link but a simple google search should do it)
- Anonymous October 22, 2013