You wouldn't get an on-site interview with this answer.

Your code is not optimal, although it looks short.

Here is the trick: you don't have to traverse entire tree to find out the minimum.

think about this example. L side of the root node has only one item, so the deep is 1, R side of the root has one million items. Why do you have to traverse through all one million nodes, if you can get the min from the L side right away?

isn't this?

int mindepth(node* root)

{

if(root==NULL) return 0;

return 1 + min(mindepth(root->left),mindepth(root->right));

}