FunctionRacerProblemsRace

Shorten the Longest Gap

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

stops lists the positions of the bus stops along a road, in increasing order. You may build extra more stops anywhere along the road, also between whole positions.

Return the smallest possible length of the longest gap between two neighboring stops, as a float.

Example 1

stops [0,10,12]
extra 1
returns 5.0

Build the stop at 5. The gaps are then 5, 5 and 2.

Example 2

stops [0,3,9]
extra 2
returns 3.0

Both new stops go between 3 and 9, which leaves three gaps of 2 there. The gap from 0 to 3 is now the longest.

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