Adobe Interview Question

Iterative method to find the height of a tree

Interview Answers

Anonymous

Sep 18, 2013

Hi, When were you told about the result.. right after HR round? Actually I have appeared for 5 tech rounds and HR round and waiting for result. Thus wanted to know.

Anonymous

Mar 3, 2012

/** Returns the max root-to-leaf depth of the tree. Uses a recursive helper that recurs down to find the max depth. */ public int maxDepth() { return(maxDepth(root)); } private int maxDepth(Node node) { if (node==null) { return(0); } else { int lDepth = maxDepth(node.left); int rDepth = maxDepth(node.right); // use the larger + 1 return(Math.max(lDepth, rDepth) + 1); } }

2