Problem, as an interviewer would state it: "Given the root of a binary tree, determine whether it is a valid binary search tree. Discuss edge cases, runtime, and alternative approaches."
Examples:
2 5
/ \ / \
1 3 1 4 <- 4 is smaller than 5: invalid
/ \
3 6
Clarifying questions expected:
- Are duplicate values allowed, and if so on which side?
- Does the tree need to satisfy the ordering for the WHOLE left and right subtrees, not just the immediate children?
- How deep can the tree be (recursion limits)?
Code / implementation expected: Yes — real, direct proof against an independent oracle, plus the tree that a naive check gets wrong.