146. Given a binary tree, and 3 values A,B and C. write an .......
Microsoft Interview Questions and Answers
(Continued from previous question...)
146. Given a binary tree, and 3 values A,B and C. write an
.......
Question:
Given a binary tree, and 3 values A,B and C. write an
algorithm to check if there exists a path from A to C
such that B lies in the path.
maybe an answer:
Find(Node n,Node req){
if(n==null)
return false;
if(req==A)
if(n==A)
return Find(n,B);
if(req==B)
if(n==B)
return Find(n,C);
if(req==C)
if(n==C)
return true;
else
return Find(n.left,req)||Find(n.right,req);
}
(Continued on next question...)
Other Interview Questions
|