FunctionRacerProblemsRace

Widest Gap After Sorting

BeginnerSorting and searchingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems