Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains fewer than two elements, return 0. You must write an algorithm that runs in linear time and uses linear extra space.
Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains fewer than two elements, return 0. You must write an algorithm that runs in linear time and uses linear extra space.
Example 1:
Input: {"nums":[3,6,9,1]}
Output: 3
Constraints:
1≤nums.length≤105
0≤nums[i]≤109
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[3,6,9,1]}
We want the widest jump between neighbours once nums is sorted, without actually sorting. There are 4 numbers.