Back to problems Solve on LeetCode →

Validate Binary Search Tree

LeetCode 98 • Medium • Trees

Inorder must be strictly increasing. Iterative: stack + prev; recursive: DFS with (min, max) bounds. Tree [5,1,4,null,null,3,6] is invalid (3 < 5).

TimeO(n)inorder visit each node
SpaceO(h)stack depth
prev: Stack:
prev
Current node
Stack
Invalid
prev
Stack
Ready
Press Play. Inorder: push left, pop, check node > prev, push right. BST = strictly increasing inorder.