Shorten the Longest Gap
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
2 <= len(stops) <= 2000 <= stops[i] <= 10**9, strictly increasing1 <= extra <= 10**6
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Two Teams of Equal SizeHard
- Height CheckerBeginner
- Kth Largest ElementBeginner
- Kth Smallest Distinct ValueBeginner
- Maximum Product of Two ElementsBeginner
- Median of the ListBeginner
- Names in OrderBeginner
- Shortest Words FirstBeginner