23 · Binary Search Trees

#530 Minimum Absolute Difference in BST

Easysolve on LeetCode ↗

frequently reported atGoogleAmazon

the problem

In plain words

Given the root of a BST with at least two nodes, return the smallest difference between the values of any two different nodes.

in root = [4,2,6,1,3]

out 1

Sorted values 1, 2, 3, 4, 6: neighbours differ by 1, 1, 1, 2.

in root = [1,0,48,null,null,12,49]

out 1

48 and 49.

  • 2 ≤ number of nodes ≤ 10⁴
  • 0 ≤ Node.val ≤ 10⁵
  • Same problem as LC 783 (Minimum Distance Between BST Nodes)

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #98
    2. #230
    3. #94