Fastest Airport Route Using at Most K Toll Roads
Last updated: November 29, 2026
Quick Overview
Roads between intersections are undirected with travel times, and some are toll roads. A rider's preference allows at most K toll roads. Return the minimum travel time from source to destination respecting that limit, or -1 if unreachable.
Uber
November 29, 20260
0
0 solved
Roads between intersections are undirected with travel times, and some are toll roads. A rider's preference allows at most K toll roads. Return the minimum travel time from source to destination respecting that limit, or -1 if unreachable.
Uber lets riders and drivers avoid tolls, and this onsite problem generalizes that into a resource-constrained shortest path. The interviewer wants the state-expanded graph (node, tolls used) and a discussion of why plain Dijkstra on nodes alone is wrong.
What the Interviewer Expects
- Explains why tracking only the best time per node is incorrect
- Expands state to (node, tolls used)
- Runs Dijkstra on the expanded state space
- Stops at the first time the destination is popped
- Analyzes the K factor in complexity
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 if tolls have prices and you minimize time subject to a budget?
- How would you return the actual route?
- Can you prune states dominated by a faster arrival with fewer tolls?
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, minutes, is_toll), src, dst, K >= 0. Output: minimum minutes or -1. Weights are non-negative....
High-Level Design
A node reached faster using more tolls is not strictly better than one reached slower using fewer, because the remaining budget matters. So the state is (node, used), with used from 0 to K. Run Di...