Count Distinct Fastest Routes Between Two Bing Maps Intersections

Last updated: November 29, 2026

Quick Overview

Given an undirected road graph with travel times, count how many different routes from src to dst achieve the minimum total travel time. Return the count modulo 1,000,000,007.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given an undirected road graph with travel times, count how many different routes from src to dst achieve the minimum total travel time. Return the count modulo 1,000,000,007.

Microsoft onsites pick this kind of question for maps and routing teams, since it combines Dijkstra with dynamic programming over the shortest path DAG. The interviewer checks how ties are handled and why counts are only final once a node is popped.

What the Interviewer Expects
  • Run Dijkstra and maintain a ways count per node
  • Reset the count on a strictly shorter distance and add on an equal distance
  • Explain why counts propagate correctly in pop order
  • Apply the modulus
  • Mention why BFS is not enough with non-unit weights
Key Topics to Cover
Dijkstra
dynamic programming
counting paths
weighted graphs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you count routes that are within 10 percent of the fastest?
  • What if some roads are one way?
  • How would you list the top three distinct routes?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Inputs: n intersections, undirected roads [u, v, time] with positive times, src and dst.
  • Two routes differ if their sequences of intersections differ.
  • Output: number of routes with minimum tot...
High-Level Design

The fastest routes form a DAG: an edge u to v is on some fastest route exactly when dist[u] + t == dist[v]. Counting paths in that DAG is a DP in increasing distance order, which is the order Dijkst...


Submit Your Answer
Markdown supported