Minimum absolute difference in BST

TopicDifficultyCompanies
Binary Search Tree
EASY
Google

Given a binary search tree with root node having non-negative values, write a program to find the minimum absolute difference between values of any two nodes.

Problem Note

  • There are at least two nodes in the BST.

Example 1

Input: Given binary search tree
7
/ \
3 10
/ \ / \
2 5 8 12

Output: 1
Explanation: The minimum absolute difference is 1, which is the difference between 8 and 7 (or between 2 and 3).

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.