You are viewing a single comment's thread. Return to all comments →
Consider the below 2 types of trees, you will know where you went wrong.
Case 1 :
20 / \ 10 2
Case 2:
18 / \ 8 20 / \ 10 30
Alright I got it we have to find the minimum from left sub tree and the maximum from the right one Thanks!
Yes correct !
Isn't it that all nodes in left tree should be less than root and right should be greater than root. Than why we need to find min and max.
Is it not the other way? minimum from right sub tree must be greater than root and maximum from left subtree must be less than root
Got it. thanks a lot.
Thanks for case 2 visualization, this explains why my code failed a bunch of test cases.
Can anyone please tell me what's wrong in his code? What t understand from these two test-cases?
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Consider the below 2 types of trees, you will know where you went wrong.
Case 1 :
Case 2:
Alright I got it we have to find the minimum from left sub tree and the maximum from the right one Thanks!
Yes correct !
Isn't it that all nodes in left tree should be less than root and right should be greater than root. Than why we need to find min and max.
Is it not the other way? minimum from right sub tree must be greater than root and maximum from left subtree must be less than root
Got it. thanks a lot.
Thanks for case 2 visualization, this explains why my code failed a bunch of test cases.
Can anyone please tell me what's wrong in his code? What t understand from these two test-cases?