FunctionRacerProblemsRace

Spread the Tents

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

spots lists the places along a path where a tent can stand. They are all different and in no particular order. Put up tents tents, each on its own spot, so that the two tents closest to each other are as far apart as possible.

Return that distance.

Example 1

spots [1,2,4,8,9]
tents 3
returns 3

Tents at 1, 4 and 8 are at least 3 apart. No three spots are all at least 4 apart.

Example 2

spots [10,0]
tents 2
returns 10

Both spots are used, and they are 10 apart.

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