Skip to content

Commit c85830b

Browse files
committed
Updates leetcode/binary-search/774-minimize-max-distance-to-gas-station.md
Auto commit by GitBook Editor
1 parent 2d11e40 commit c85830b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

leetcode/binary-search/774-minimize-max-distance-to-gas-station.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[https://leetcode.com/problems/minimize-max-distance-to-gas-station/description/](https://leetcode.com/problems/minimize-max-distance-to-gas-station/description/)
44

5-
On a horizontal number line, we have gas stations at positions stations\[0\], stations\[1\], ..., stations\[N-1\], where N = stations.length.
5+
On a horizontal number line, we have gas stations at positions stations\[0\], stations\[1\], ..., stations\[N-1\], where N = stations.length.
66

7-
Now, we add K more gas stations so that D, the maximum distance between adjacent gas stations, is minimized.
7+
Now, we add K more gas stations so that D, the maximum distance between adjacent gas stations, is minimized.
88

99
Return the smallest possible value of D.
1010

@@ -32,7 +32,14 @@ Output: 0.500000
3232
4. Then the answer will be on top of the heap
3333
5. Time complexity O\(Klogn\)
3434
6. Space complexity O\(n\)
35-
3. ASD
35+
3. Binary Search
36+
1. Using the boundaries of stations, the possible width will be in between 0 and 1e8
37+
2. Perform binary search on the width within these boundaries, we will narrow down our search until these boundaries differ less than our desired delta
38+
3. Now the conditions to narrow our search to left or right depends on a separate function possible\(mi, stations, K\), where it check if we can use less than or equal to K stations to achieve the mi distance
39+
4. If possible return true, we set hi = mi to find better distance
40+
5. Else we set lo = mi
41+
6. Time complexity O\(nlogW\), where w = 1e8/1e-6 = 1e14
42+
7. Space complexity O\(1\)
3643

3744
### Solution
3845

0 commit comments

Comments
 (0)