Dashboard
LC #98

Validate Binary Search Tree

Pattern · ?AmazonGoogleMetaMicrosoft

Problem

Determine if a binary tree is a valid BST.

Constraints

  • 1 ≤ n ≤ 10⁴
  • -2³¹ ≤ Node.val ≤ 2³¹ − 1
  • All values must be strictly less/greater (no equal values)

Example

Input
root = [5, 1, 4, null, null, 3, 6]
Output
false
Why
Root is 5 but right child is 4 (4 < 5 violates BST property)

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗