140. Minimize Max Distance to Gas Station

HardArrayArray

Given sorted gas station positions and k new stations to add, minimize the maximum distance between adjacent stations. Return the minimized maximum distance scaled by 10^6 and rounded to the nearest integer (to keep deterministic integer output). Input: '[stations], k'.

Input: '[stations], k'.

Output: Integer — minimized max distance times 10^6.

Examples

Example 1
Input: [1,2,3,4,5,6,7,8,9,10], 9
Output: 500000
Explanation: Half-unit spacing -> 0.5 * 10^6.
Example 2
Input: [1,100], 1
Output: 49500000
Explanation: 49.5 * 10^6.

Constraints

Asked by

GoogleAmazon
Solve this problem in the editor →