Different answer on run as custom input and submit


#1

int m=0;
void depth(TreeNode* node,int n){
if(node){
n++;
if(m<n) m=n;
depth(node->left,n);
depth(node->right,n);
}
}

int Solution::maxDepth(TreeNode* A) {

depth(A,0);
return m;

}


#2

Every single question on interviewbit has this exact same doubt. How difficult is it to just clear your global variables? Or even better, not use global variables at all except when absolutely necessary (which is not the case in this question). Try a simple one line recursive solution.