Largest BST in a binary tree

ret.min = min(l.min, min(r.min, root->data));
ret.max = max(r.max, max(l.max, root->data));

why we write like this because as if know it is BST it is obvious that min = left.min and max = right.max ?

source - https://www.geeksforgeeks.org/largest-bst-binary-tree-set-2/

Hello @Rakshitgarg99,

This is done to handle the case, when the root has only one child.

Hope, this would help.


please look this also which one is correct way to write these statements then

Hello @Rakshitgarg99,

Following code is passing all the test cases:
And it follows the second method:

Hope, this would help.

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.

it has so many errors before putting your code please do check it once