Amazon Interview Question

Code to get the depth of a binary tree.

Interview Answers

Anonymous

Sep 7, 2011

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

Anonymous

Jul 8, 2011

should be easy if you have done it before.