https://ide.codingblocks.com/s/452847 one testcase not passing
Largest BST in a Binary tree
hello @hrithik-1
checking left node and right node data is not the sufficient condition of bst.
the correct condition is .
largest node in left subtree must be less than current node and smallest node in right subtree must be greater than current node.
if both condition holds and left and right subtree are also bst then only u can say tree starting from current node as bst
still not passing the last test case
pls share updated code.
no thats not right.
see u need to return following things from ur subtree.
int sz; // Size of subtree
int max; // Min value in subtree
int min; // Max value in subtree
int ans; // Size of largest BST which
// is subtree of current node
bool isBST; // If subtree is BST
based on these information u need to decide answer for current subtree.
if still not clear then pls refer this->link
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.