Widest Gap After Sorting
Put the numbers of nums in order from smallest to largest and look at each pair of neighbors in that order. Return the largest difference between two neighbors.
nums has at least two items. Equal numbers are neighbors with a difference of 0.
Example 1
nums [8,1,4]
returns 4
In order the numbers are 1, 4, 8. The gaps are 3 and 4, and the widest is 4.
Example 2
nums [5,5,5]
returns 0
All the numbers are equal, so every gap is 0.
Example 3
nums [10,3]
returns 7
Two numbers have one gap: 10 - 3 = 7.
Constraints
2 <= len(nums) <= 30-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.