#C10053. Minimum Absolute Difference of Potions
Minimum Absolute Difference of Potions
Minimum Absolute Difference of Potions
You are given n potions with their potency values. Your task is to compute the minimum absolute difference between the potency values of any two potions. This difference is defined as the absolute value of the subtraction between any two distinct elements in the list.
To solve the problem efficiently, you can sort the list of potencies first. Once sorted, the minimum absolute difference will be among consecutive elements in the sorted list. Use this property to implement a solution with optimal performance.
Example:
Input: 5 8 -3 1 0 -4</p>Output: 1
inputFormat
The first line contains an integer n, the number of potions. The second line contains n space-separated integers representing the potency values of each potion.
Constraints: 2 ≤ n ≤ 105. The potency values can be negative, zero, or positive.
outputFormat
Output a single integer: the minimum absolute difference between the potency values of any two potions.
## sample5
8 -3 1 0 -4
1