Valid Binary Search Tree

Asked atHubSpot
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Carry an exclusive lower and upper bound into each node.
  2. 02Reject a value outside its bounds.
  3. 03Recurse left with current value as upper bound.
  4. 04Recurse right with current value as lower bound.

Reference answer

Then expect these follow-ups

  • How can inorder traversal validate a BST?

    Tests: ordering

  • How do duplicates change the bounds?

    Tests: specification

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question