Added helper function to determine if a tree is a valid BST