 All Problems
Number of Ways to Arrive at Destination
medium
topological sort
graph
shortest path
dynamic programming
amazon
google
uber
lyft

You are in a city with n intersections (0 to n-1) and bidirectional roads with travel times. Find the number of ways to reach intersection n-1 from intersection 0 in the shortest amount of time. Return the count modulo 10^9 + 7.

Example:

Input: n=7, roads=[[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]
Output: 4

Constraints:

  • 1 <= n <= 200
  • 1 <= roads.length <= n*(n-1)/2
Run to check your code against the sample cases, or submit to run every case