Amazon Interview Question: Binary Tree - Common Ancestor... | Glassdoor

Interview Question

Software Engineer Interview Seattle, WA

Binary Tree - Common Ancestor of two nodes


Interview Answer

3 Answers


Find path to each of the two nodes and load both paths into the arraylist. Loop over arraylists and find the common nodes in the path. Pick the last common node.

Interview Candidate on May 14, 2014

this is to much should use a recursive solution.

Matteo Gobbi on Jun 15, 2014

his solution is log(n) (balanced tree) and very intuitive and simple.

funny on Jul 8, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.