Count Distinct Fastest Routes Between Pickup and Dropoff
Last updated: November 29, 2026
Quick Overview
Given an undirected road graph with positive travel times, count how many distinct routes from the pickup node to the dropoff node achieve the minimum total travel time. Return the count modulo 1,000,000,007.
Uber
November 29, 20260
0
0 solved
Given an undirected road graph with positive travel times, count how many distinct routes from the pickup node to the dropoff node achieve the minimum total travel time. Return the count modulo 1,000,000,007.
An Uber technical screen variant of Dijkstra, motivated by offering riders alternative routes with the same ETA. The interviewer checks that you carry a path count alongside the distance and reset it on a strict improvement.
What the Interviewer Expects
- Extends Dijkstra with a ways array
- Resets ways on a strictly shorter distance
- Adds ways on an equal distance
- Processes each node only after its distance is final
- Applies the modulus
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
- How would you count routes within 5 percent of the fastest?
- Why does this need positive weights, and what breaks with zero-weight edges?
- How would you sample one fastest route uniformly at random?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: n, roads as (u, v, t) with t > 0, src, dst. Output: number of shortest paths mod ; 0 if unreachable. Two routes are distinct if their edge sequences differ....
High-Level Design
Shortest paths form a DAG where every edge u -> v satisfies dist[u] + w = dist[v]. Dijkstra visits nodes in increasing distance, which is a topological order of that DAG. So when relaxing edge `u ...