Given the root of a binary tree, find the largest subtree that is a valid Binary Search Tree (BST), and return the total number of nodes in that subtree.
Note: A subtree consists of a node and all of its descendants. A valid BST requires that for every node, all values in its left subtree are strictly smaller than the node’s value, and all values in its right subtree are strictly greater than the node’s value.
Constraints:
The number of nodes in the tree is in the range
Node.val
Given the root of a binary tree, find the largest subtree that is a valid Binary Search Tree (BST), and return the total number of nodes in that subtree.
Note: A subtree consists of a node and all of its descendants. A valid BST requires that for every node, all values in its left subtree are strictly smaller than the node’s value, and all values in its right subtree are strictly greater than the node’s value.
Constraints:
The number of nodes in the tree is in the range
Node.val