lodown414
BAN USER
Comments (3)
Reputation 40
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Start by adding the pointer to a stack. Add pointers of parents to the stack until you reach to root. You can then start at the root and search for the data value of the second node. If the top of the stack is the same as a node in the path, you pop. once you stop popping, you have found the most common ancestor (you must keep track of the last popped node to put it back on the stack). If you do not find a common ancestor but have found the initial node, your value is a descendant of it and you can continue adding pointers to your stack resulting in a stack with your path. O(logN).
- lodown414 January 04, 2013Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Min (| value(C) - value(B) | ). what does this mean?
- lodown414 January 07, 2013