Amazon.com

  www.amazon.com
  www.amazon.com

Interview Question

Software Engineer Interview Seattle, WA

Binary Tree - Common Ancestor of two nodes

Answer

Interview Answer

3 Answers

1

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
0

this is to much extensive..you should use a recursive solution.

Matteo Gobbi on Jun 15, 2014
1

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.