Given the root of a binary tree, find the largest subtree, which is also a Binary Search Tree (BST), where the largest means subtree has the largest number of nodes.
A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties:
The left subtree values are less than the value of their parent (root) node’s value.
The right subtree values are greater than the value of their parent (root) node’s value.
Note: A subtree must include all of its descendants.
Follow up: Can you figure out ways to solve it with O(n) time complexity?
Input: root = [10,5,15,1,8,null,7]
Explanation: The Largest BST Subtree in this case is the highlighted one. The return value is the subtree's size, which is 3.