Given a table Point with a single column x representing positions on the X-axis, find the shortest distance between any two points.
Each row contains an integer value representing the position of a point on the X-axis. You need to calculate the minimum absolute difference between any two distinct points.
Note: The result should be the minimum distance value as a single number.
Table Schema
| Column Name | Type | Description |
|---|---|---|
x
PK
|
int | Position of point on X-axis (primary key) |
Input & Output
| x |
|---|
| -1 |
| 0 |
| 2 |
| shortest |
|---|
| 1 |
Points are at positions -1, 0, and 2. The distances are: |(-1)-0| = 1, |(-1)-2| = 3, |0-2| = 2. The shortest distance is 1 between points -1 and 0.
| x |
|---|
| 1 |
| 3 |
| 6 |
| 10 |
| shortest |
|---|
| 2 |
Points at 1, 3, 6, 10. Distances: |1-3| = 2, |1-6| = 5, |1-10| = 9, |3-6| = 3, |3-10| = 7, |6-10| = 4. The shortest is 2 between points 1 and 3.
| x |
|---|
| 5 |
| 8 |
| shortest |
|---|
| 3 |
With only two points at positions 5 and 8, the distance is |5-8| = 3.
Constraints
-
2 ≤ number of points ≤ 500 -
-10^8 ≤ x ≤ 10^8 - All points have unique x coordinates