Minimum Absolute Difference in BST

Minimum Absolute Difference in BST is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Tree Traversal Patterns (DFS & BFS) pattern, in the Recursive Inorder Traversal subpattern.

Problem statement

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.

Example 1:

Input: root = [4,2,6,1,3] Output: 1

Example 2:

Input: root = [1,0,48,null,null,12,49] Output: 1

Constraints:

- The number of nodes in the tree is in the range [2, 104].

- 0 <= Node.val <= 105

Note: This question is the same as 783: https://leetcode.com/problems/minimum-distance-between-bst-nodes/

Topics and companies

Topics: Tree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree.

Reported in interviews at Google.

How to practise Minimum Absolute Difference in BST on Thita.ai

Starter code is provided in C, C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n) time and O(h) space.

Open Minimum Absolute Difference in BST in the code editor, or read the Minimum Absolute Difference in BST editorial for a worked solution with its approach and complexity analysis.

Where Minimum Absolute Difference in BST sits in the DSA pattern sheet

Problems related to Minimum Absolute Difference in BST

Other problems that use the same Recursive Inorder Traversal and Tree Traversal Patterns (DFS & BFS) techniques:

Preparing your workspace

Progress is saved as you study.