Cheapest Lane-Level Route With Lane Change Penalties
Last updated: November 29, 2026
Quick Overview
Given a lane graph where each lane has successor lanes with lengths and adjacent lanes reachable by a lane change with a fixed penalty, find the minimum-cost lane sequence from a start lane to any lane in a goal set (for example an exit ramp).
Aurora
November 29, 20260
0
0 solved
Given a lane graph where each lane has successor lanes with lengths and adjacent lanes reachable by a lane change with a fixed penalty, find the minimum-cost lane sequence from a start lane to any lane in a goal set (for example an exit ramp).
Route planning for a heavy truck is lane-level: a Class 8 truck wants to minimize lane changes and must be in the right lane well before an exit. This onsite question checks whether you can model two edge types in one graph, apply Dijkstra correctly, and reconstruct the path.
What the Interviewer Expects
- Models successor edges and lane change edges in one weighted graph
- Implements Dijkstra with a heap and lazy deletion of stale entries
- Supports multiple goal lanes
- Reconstructs the path with a predecessor map
- Returns a clear result when no route exists
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 forbid a lane change within 300 m of the exit gore?
- Lane change cost should depend on traffic density: how does that change the algorithm?
- How would you use A* here and what heuristic is admissible?
- How would you precompute routes over a whole Texas freight corridor?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
successors[lane] is a list of (next_lane, length_m); neighbors[lane] lists lanes reachable by one lane change, each costing change_cost. Return (cost, path) or (inf, []). All costs are non...
High-Level Design
Treat a lane as a node. Out-edges are successors (cost = length) plus lane changes (cost = penalty). Run Dijkstra from the start and stop the first time a goal lane is popped, because at that moment i...