Amazon interview question

Code to get the depth of a binary tree.

Interview Answers

Anonymous

7 Sept 2011

int depth(node * root) { if (root == null) return 0; return max(depth(root->left), depth(root->right) + 1; }

Anonymous

8 Jul 2011

should be easy if you have done it before.