Phase 0: Meet the candidate tree and predict validity
Validate Binary Search Tree (LC 98)
A tree that breaks every test you write
A Binary Search Tree has one rule: every node's left subtree is STRICTLY LESS than the node, and every node's right subtree is STRICTLY GREATER. Given a tree, return true if it satisfies the rule everywhere — false otherwise.
Here is the tree. Five values, four edges, two levels of children. Look at every parent and its children below — does anything look wrong?
FIG. 1 — THE CANDIDATE TREE
The BST rule sounds simple — left smaller, right bigger. But there is a subtlety in that definition that trips most implementations. Look carefully at the tree before you commit.
Is this a valid Binary Search Tree? Check every parent against its children before you commit.