We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Use java 7.
I tried below code, it is passing with custom test case with SAME DATA but fails for same data( 5 test failing) in their automation.
Not sure why hacker rank guys are not fixing it...
boolean checkBST(Node root) {
if (null == root){
return true;
}
//System.out.println("Processing..." + root.data);
boolean ret = true;
if (null != root.left){
if (root.left.data >= root.data){
ret = false;
//System.out.println("NOT_OK:Left is bigger or equal:" + root.left.data);
} else {
//System.out.println("OK:Left is small:" + root.left.data);
}
}
if (null != root.right){
if (root.right.data <= root.data){
ret = false;
//System.out.println("NOT_OK:Right is smaller or equal:" + root.right.data);
} else {
//System.out.println("OK:Right is big:" + root.right.data);
}
}
//if false return here
if(!ret){
return false;
}
return checkBST(root.left) && checkBST(root.right);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Use java 7. I tried below code, it is passing with custom test case with SAME DATA but fails for same data( 5 test failing) in their automation. Not sure why hacker rank guys are not fixing it...