Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Number of Refueling Stops
Bookmark
Input
Example 1
Impossible
Already there
Two stations
Custom
target
=
100
,
startFuel
=
10
,
stations
=
[[10,60],[20,30],[30,30],[60,40]]
0
target 100
60
10
30
20
30
30
40
60
car
0
target 100
60
10
30
20
30
30
40
60
car
stops =
0
fuel =
10
0
target 100
60
10
30
20
30
30
40
60
car
fuel =
10
, target =
100
, stops =
0
stops =
0
fuel =
0
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+60
pass without stopping → bank
+60
for later
stops =
0
fuel =
-10
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+60
drive 10 → 20: fuel
0
−
10
=
-10
— ran dry!
stops =
1
fuel =
50
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+30
pass without stopping → bank
+30
for later
stops =
1
fuel =
40
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+30
drive 20 → 30: fuel
50
−
10
=
40
stops =
1
fuel =
10
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+30
+30
drive 30 → 60: fuel
40
−
30
=
10
stops =
1
fuel =
10
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+40
+30
+30
pass without stopping → bank
+40
for later
stops =
2
fuel =
10
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+40
+30
+30
biggest can
+40
→ fuel =
10
, stops =
2
stops =
2
fuel =
10
0
target 100
60
10
30
20
30
30
40
60
car
fuel cans
+30
+30
Minimum stops = 2
algo
master
.
io
Step:
Start: Reach position 100 with the fewest refueling stops
0 / 13
Input
Example 1
Impossible
Already there
Two stations
Custom
target
=
100
,
startFuel
=
10
,
stations
=
[[10,60],[20,30],[30,30],[60,40]]
0 / 13
algo
master
.
io
Step:
Start: Reach position 100 with the fewest refueling stops