getting wrong answer while logic seems to correct.
Largest BST in Tree
@RULEREMPIRES Hi bro, first of all your build tree is wrong, secondly, for test case:-
3
4 3 5
3 4 5
Your answer :- 2
Correct :- 3 because 3 nodes are making biggest bst.
For correct build tree refer this:-
@RULEREMPIRES Bro first of all, you don’t have to close and reopen the doubt, just drop a comment we will be notified. Lemme check!
@RULEREMPIRES Ya logic is wrong, Check for this test case:-
9
50 30 5 20 60 45 70 65 80
5 30 20 50 45 60 65 70 80
Your output :- 7
Correct Output :- 5
Your recursive calls are wrong, the left subtree leaf nodes are getting added up, which is wrong!
Dry run it you will know!