Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
This is the exact solution i have given..and then he asked me about run time complexity ...i said O(n)
boolean tree_compare(Node t1, Node t2){
if(t1==null && t2 == null) return true;
if(t1 ==null || t2 == null) return false;
return (t1.val == t2.val) && tree_compare(t1.left, t2.right) && tree_compare(t1.right, t2.left)
i think mike your solution will just compare two similar trees....i think this is not for finding whether two binary trees are mirror images of each other....
boolean tree_compare(Node t1, Node t2){
if(t1==null && t2 == null)
return true;
if(t1 ==null || t2 == null)
return false;
return (t1.val == t2.val) && tree_compare(t1.left, t2.right) && tree_compare(t1.right, t2.left)
- Mike1324 December 11, 2012