please tell me what i am doing wrong
Https://ide.codingblocks.com/s/159868
@sarthaksingh
First of all , you are required to print the count of the no of nodes in the largest BST. Secondly , your recursive function is wrong. Consider the case when the tree formed by your root node is not a BST but one of its subtrees is a BST. In that case , you should print the size of that BST subtree. However in your code the else condition would be hit which would simply return 0.
i understand what you are telling but to counter that i have made recursive call and it each step i am storing maximum value by making global variable
@sarthaksingh
But that doesn’t solve the problem. As you can see the result you would be obtaining from your recursive calls would be wrong due to the case mentioned above. So even though you are storing ans in a global variable , the value for that global variable is obtained from recursive calls only. If you are getting wrong results from your recursive calls , how can your global variable store the right answer in the first place ?
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.