127. Minimum Number of Refueling Stops

HardArrayArray

A car starts with startFuel and must reach target. Stations are [position, fuel] pairs. Each unit of fuel moves 1 unit. Return the minimum number of refueling stops to reach target, or -1 if impossible. Input: 'target, startFuel, [[pos,fuel],...]'.

Input: 'target, startFuel, [[pos,fuel],...]'.

Output: Integer stops or -1.

Examples

Example 1
Input: 1, 1, []
Output: 0
Explanation: Already enough fuel.
Example 2
Input: 100, 1, [[10,100]]
Output: -1
Explanation: Can't reach first station.
Example 3
Input: 100, 10, [[10,60],[20,30],[30,30],[60,40]]
Output: 2
Explanation: Refuel at stations to reach target.

Constraints

Asked by

MicrosoftAmazonInfosysBloombergGoogle
Solve this problem in the editor →