Check if BST is Valid

00:00
MediumTreeDFSRecursionBST
AmazonMicrosoftAdobe

Determine if a binary tree is a valid Binary Search Tree (BST). Each node must satisfy: all left descendants < node < all right descendants.

Examples

Input → [2,1,3]
Output → True
Input → [5,1,4,null,null,3,6]
Output → False
Note: 4 is in right subtree of 5 but 4 < 5
Input → [2,2,2]
Output → False
Note: equal values violate BST