#K58647. Maximum Successive Gap

    ID: 30689 Type: Default 1000ms 256MiB

Maximum Successive Gap

Maximum Successive Gap

You are given an array of n integers. Your task is to compute the maximum difference between successive elements when the array is sorted in non-decreasing order. If the array contains fewer than two elements, the answer should be 0.

Formally, let the sorted array be \(a_1, a_2, \dots, a_n\). You need to find the maximum value of \(a_{i+1} - a_i\) for \(1 \le i \lt n\).

You must read the input from stdin and output the result to stdout.

inputFormat

The first line of input contains an integer n representing the number of elements in the array. The second line contains n space-separated integers which are the elements of the array.

Example:

4
3 6 9 1

outputFormat

Output a single integer which is the maximum difference between successive elements in the sorted array. If there are fewer than two elements, output 0.

Example:

3
## sample
4
3 6 9 1
3

</p>