Fastest Navigator Route Using At Most K Toll Roads
Last updated: November 29, 2026
Quick Overview
Given an undirected road graph where each edge has travel time in minutes and a toll flag, find the minimum travel time from source to destination using at most k toll edges, or -1 if impossible.
Yandex
November 29, 20260
0
0 solved
Given an undirected road graph where each edge has travel time in minutes and a toll flag, find the minimum travel time from source to destination using at most k toll edges, or -1 if impossible.
Yandex Navigator offers routing options such as avoiding toll roads, and a constrained shortest path is a strong onsite graph problem. The interviewer checks that you expand the state space correctly rather than running plain Dijkstra and patching the result.
What the Interviewer Expects
- Recognize that plain Dijkstra fails because the cheapest path may exhaust the toll budget
- Model the state as (node, tolls_used) with k+1 layers
- Run Dijkstra on the layered graph with lazy deletion
- Return early when the destination is popped
- State O((V k + E k) log(V k)) 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
- How would you instead minimize time plus a money cost per toll with a user-chosen weight?
- The real road graph has tens of millions of nodes; what preprocessing (contraction hierarchies, landmarks) would you use?
- How do live traffic speeds change the edge weights and the preprocessing?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Nodes 0..n-1, edges (u, v, minutes, is_toll), non-negative weights. Find the minimum time path from src to dst whose number of toll edges is at most k....
High-Level Design
Make k+1 copies of the graph. State (v, t) means at node v having used t tolls. A free edge stays in the same layer, a toll edge moves from layer t to t+1, and edges leaving layer k on a toll are fo...