I went straight for the naive approach, checking left child less than root and right child greater than root at each node.
Clarify the definition of a BST (strict ordering, no duplicates) and then propose a recursive solution that passes down a valid range (min, max) for each node. Alternatively, use an in-order traversal to check if the sequence is strictly increasing. Discuss time and space complexity, and handle edge cases like empty tree or single node.
Pro tip: Mention that a common mistake is only checking immediate children; instead, emphasize that each node must satisfy constraints from all ancestors. Also, consider iterative in-order traversal to achieve O(1) space if recursion stack is a concern.
Ask whether duplicates are allowed and if the BST definition is strict (left < root < right). Confirm input format and expected output.
Decide between recursive range-checking or iterative in-order traversal. Explain trade-offs in time/space complexity.
Write clean code with helper functions. For range-checking, pass min and max bounds; for in-order, track previous node value.
Walk through edge cases: empty tree, single node, invalid BST where a node violates ancestor constraints, and tree with duplicates (if allowed).
State time complexity O(n) and space complexity O(h) for recursion or O(1) for iterative with Morris traversal. Discuss optimizations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.