Practice Count All Possible Routes
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively. At each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.length and move to city j. Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|. Please notice that |x| denotes the absolute value of x. Notice that fuel cannot become negative at any point in time, and that you are allowed to visit any city more than once (including start and finish). Return the count of all possible routes from start to finish. Since the answer may be too large, return it modulo 10^9 + 7.
Source: Count All Possible Routes on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5
4
# Example 2
locations = [4,3,1], start = 1, finish = 0, fuel = 6
5
# Example 3
locations = [5,2,1], start = 0, finish = 2, fuel = 3
0
Constraints
Related LeetCode Problems
Practice more problems similar to Count All Possible Routes.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.