#C4577. Smallest Difference Between the Two Highest Quantities
Smallest Difference Between the Two Highest Quantities
Smallest Difference Between the Two Highest Quantities
Given a list of n ingredient quantities, your task is to compute the smallest difference between the two highest quantities in the list.
More formally, let the quantities be represented as a list Q = [q_1, q_2, \dots, q_n]. Define q_max as the maximum element in Q and q_{2max} as the second highest element. You are required to compute the value of:
$$|q_{max} - q_{2max}|$$
Please note that if all quantities are identical, the result is 0.
inputFormat
The first line of input contains an integer n representing the number of ingredients.
The second line contains n space-separated integers representing the quantities of the ingredients.
outputFormat
Output a single integer, which is the smallest difference between the two highest ingredient quantities.
## sample5
3 1 9 7 8
1