Back to problems Sign in to unlock
Leetcode
Medium
Trees
Binary Search
Minimum Absolute Difference in BST
Find the smallest absolute difference between values of any two nodes in a binary search tree.
Acceptance 0%
Problem Statement
Given the root of a binary search tree (BST), determine the minimum absolute difference between the values of any two distinct nodes.
Because values in a BST are ordered by an inorder traversal, the key is to compare neighboring values in sorted order rather than checking every pair.
Input Format
- A binary search tree rooted at
root. - Each node contains an integer value.
Output Format
- Return a single integer: the minimum absolute difference between values of any two nodes in the tree.
Constraints
- The tree contains at least 2 nodes.
- Node values are integers.
- The BST property holds for all nodes.
Examples
Sample cases returned by the problem API.
Example 1
Input
root = [4,2,6,1,3]
Output
1
Explanation
The inorder order is [1,2,3,4,6]. The smallest difference is min(2-1, 3-2, 4-3, 6-4) = 1.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.