15% off all plans & roadmaps Use code
See plansLeetCode 530 · Solution & editorial
Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.
Minimum Absolute Difference in BST is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Inorder Traversal subpattern. The pattern covers preorder, inorder, level order traversal, LCA, and serialization
Master inorder traversal for BST validation and kth element problems. Produces sorted order in BST.
The reference solution runs in O(n) time and O(h) space.
Minimum Absolute Difference in BST has been reported in interviews at Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimum Absolute Difference in BST is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Inorder Traversal subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.