Amazon Interview Question

Given a binary tree find the LCA?

Interview Answer

Anonymous

Sep 19, 2011

LCA(struct node * current, int n1, int n2) { if(current->value >=n1 && current-> val val; return; if(current->val>n1 && current->val > n2)//We know that left child is the way to proceed. LCA(current->left,n1,n2); if(current->valval right,n1,n2); }

1