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.
The right node will return true because n.right is NULL, and the left will continue searching down the three, with the max value updated to 2 (root's data value). Therefore any node whose data is greater than 2 (your last node) will return false.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
jongray93's solution returns false on your tree. In the first iteration, on the root node, the code will check the last condition:
The right node will return
true
becausen.right
isNULL
, and the left will continue searching down the three, with themax
value updated to 2 (root's data value). Therefore any node whosedata
is greater than 2 (your last node) will returnfalse
.