Given the root of a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows:

Input: root = [2,1,3]
Output: true

Input: root = [5,1,4,null,null,3,6]
Output: false
Explanation: The root node’s value is 5 but its right child’s value is 4.
From: LeetCode
Link: 98. Validate Binary Search Tree
1. Initialization: The function isValidBST initializes the validation process by calling the helper function with the entire valid integer range.
2. Base Case: If the current node is nullptr, it means we’ve reached a leaf node, and we return true since a leaf node is trivially a BST.
3. Value Check: For any other node, we check if its value lies within the permissible range (lower and upper).
4. Recursive Calls:
5. Combining Results: The final result for the current node is a logical AND (&&) of the results from the left and right subtrees. This ensures that both subtrees must be valid BSTs for the current tree to be a BST.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode* root) {
return helper(root, LONG_MIN, LONG_MAX);
}
bool helper(TreeNode* node, long long lower, long long upper) {
if (!node) return true;
if (node->val <= lower || node->val >= upper) {
return false;
}
return helper(node->left, lower, node->val) &&
helper(node->right, node->val, upper);
}
};