Largest bst in binary tree

one test case getting failed. why??

hello @rockstarpkm
there is a logical error in ur code.

if u r at particular node than for bst all value in its left subtree should be less than current node value and all value in its right subtree should be greater than current node and left and right subtree should be bst as well.

but in ur code u are only comparing current node value with value of root of left and right subtree (here is the mistake ,u need to check for each and every value in that subtree).

refer this article->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.