Back to course home
0% completed
Minimum Difference Between BST Nodes (easy)
Problem Statement
Given a Binary Search Tree (BST), you are required to find the smallest difference between the values of any two different nodes.
In a BST, the nodes are arranged in a manner where the value of nodes on the left is less than or equal to the root, and the value of nodes on the right is greater than the root.
Example
Example 1:
- Input:
4
/ \
2 6
/ \
1 3
- Expected Output: 1
- Justification: The pairs (1,2), (2,3), or (3,4) have the smallest difference of 1.
Example 2:
- Input:
10
/ \
5 15
/ \ \
2 7 18
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible