Count the Fastest Routes Between Two Points in a Map Graph
Last updated: November 29, 2026
Quick Overview
Given an undirected road graph with travel times, count how many distinct routes from intersection 0 to intersection n-1 take the minimum possible time. Return the count modulo 10^9 + 7.
Meta
November 29, 20260
0
0 solved
Given an undirected road graph with travel times, count how many distinct routes from intersection 0 to intersection n-1 take the minimum possible time. Return the count modulo 10^9 + 7.
Common in Meta technical screens as a Dijkstra extension, framed around routing for Facebook Marketplace local pickup or Meta Maps style features. The interviewer wants to see that you can carry extra state through a shortest-path run and reason about when counts become final.
What the Interviewer Expects
- Run Dijkstra while tracking a path count per node
- Reset the count on a strictly shorter distance and add on a tie
- Explain why counts are complete when a node is popped with positive weights
- Apply the modulo consistently
- Discuss why zero-weight edges would break the argument
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What goes wrong if some roads have travel time 0?
- How would you list the routes rather than count them?
- How would you count routes within 10% of the fastest time?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
nup to 200 intersections, roads(u, v, minutes)with positive times.- Count distinct paths whose total time equals the shortest time from 0 to
n - 1. - Return the count modulo
10^9 + 7....
High-Level Design
Shortest-path edges (those with dist[u] + w == dist[v]) form a DAG, and the answer is the number of source-to-target paths in it. Dijkstra visits nodes in nondecreasing distance, which is a topologi...