Amazon Interview Question
Software Engineer / Developersint max_deapth(node root){
int ld=0,rd=0,maxd=0;
node cur;
cur=root;
if(!root){
return maxd;
}
if(cur->left){
while(cur->left){
ld++;
cur=cur->left;
}
}
if(cur->right){
while(cur->right){
rd++;
cur=cur->right;
}
}
maxd = (rd > ld ? rd : ld);
return maxd+1;
}
int depth(node* root)
- winia September 17, 2008{
if(!root)
return -1;
return max(depth(root->left),depth(root->right))+1;
}