stops[i] is the coordinate of stop i, and all coordinates are distinct. You are at stop origin with fuel units of fuel and need to end up at stop target. There is no refuelling on the way.
In one move you can drive from your current stop i to any other stop j, which burns |stops[i] - stops[j]| units of fuel. Fuel can never go below zero. Any stop, including origin and target, may be visited any number of times.
A trip is a sequence of stops that starts at origin and ends at target. Count the distinct trips. The answer can be large, so return it modulo 10⁹ + 7.stops=[1, 4, 6], origin=0, target=2, fuel=5 → 2
Two trips work: 0 → 2 (5 units of fuel) and 0 → 1 → 2 (3 + 2 = 5). Any other trip needs more fuel.
stops=[10, 12], origin=0, target=0, fuel=4 → 2
You can stay put (a trip that is just stop 0) or go 0 → 1 → 0 for 4 units. That makes 2.
stops=[3, 20, 7], origin=1, target=0, fuel=16 → 0
Even the direct way from 20 to 3 costs 17, which is more than the fuel available.
stops=[1, 4, 6], origin=0, target=2, fuel=5
2
Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.