Largest BST in Tree

getting wrong answer while logic seems to correct.

@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:-

https://ide.codingblocks.com/s/286563 still last test case is giving wrong answer.

@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!

https://ide.codingblocks.com/s/287464 error not found