#C9305. Minimum Adjacent Difference in Mountain Heights

    ID: 53384 Type: Default 1000ms 256MiB

Minimum Adjacent Difference in Mountain Heights

Minimum Adjacent Difference in Mountain Heights

You are given a list of mountain heights. Your task is to determine the minimum difference between the heights of any two adjacent mountains after sorting the list in non-decreasing order. In other words, if you sort the list of heights, you need to find the smallest difference between any two consecutive elements. If there is only one mountain, the answer is 0.

Note: The minimum difference is computed on the sorted array of heights.

Example:

Input: n = 5, heights = [1, 5, 3, 4, 6]
Sorted heights = [1, 3, 4, 5, 6]
Differences = [2, 1, 1, 1]
Output: 1

inputFormat

The first line contains an integer n (the number of mountains). The second line contains n space-separated integers representing the heights of the mountains.

outputFormat

Output a single integer, the minimum difference between the heights of any two adjacent mountains after sorting the list. If there's only one mountain, output 0.

## sample
5
1 5 3 4 6
1