#C690. Maximum Gap
Maximum Gap
Maximum Gap
Given an array of integers, your task is to compute the maximum difference between two successive elements after sorting the array in non-decreasing order. Formally, if the sorted array is (a_1, a_2, \ldots, a_n), you need to find (\max_{1 \le i < n} (a_{i+1} - a_i)). If the array contains fewer than two elements, output 0. This problem challenges you to handle various types of input including duplicate and negative numbers. Although an (O(n)) solution exists, you may use any correct method given the input size constraints.
Note: The input is provided via standard input (stdin) and the result should be printed to standard output (stdout).
inputFormat
The first line contains an integer (n) (the number of elements in the array). The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the maximum gap between successive elements in the sorted order of the given array. If the array has fewer than two elements, output 0.## sample
4
3 6 9 1
3