BeingUpfront
BAN USER
- 0of 0 votes
Answerspublic interface FirstCommonAncestor {
/**
* Given two nodes of a tree,
* method should return the deepest common ancestor of those nodes.
*
* A
* / \
* B C
* / \ \
* D E H
* / \
* G F
*
* commonAncestor(D, F) = B
* commonAncestor(C, G) = A
* commonAncestor(E, B) = B
*/
Node commonAncestor(Node one, Node two);
}
- BeingUpfront in United Statesclass Node { final Node parent; final Node left; final Node right; public Node(Node parent, Node left, Node right) { this.parent = parent; this.left = left; this.right = right; } boolean isRoot() { return parent == null; } }
| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Data Structures
Open Chat in New Window