Binary Search Solution
class Solution:
def minmaxGasDist(self, A: List[int], k: int) -> float:
"""tc O(Nlg(max(A)))
1. set left, right boundry, get candidate max distance
2. count amount of gas stations to be inserted. If > K , d is to small;
"""
n = len(A)
l , r = 0, A[-1]-A[0]
while r > 1e-6 +l:
mid = (l + r)/2 #l + (r-l)/2
cnt = 0
for i in range(n-1):
cnt += ceil((A[i+1]-A[i])/mid) -1
if cnt > k:
l = mid
else:
r = mid
return l # it is guaranteened to have a result
TLE