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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Dijkstra
State-space search
Constrained shortest path
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported