Cheapest Lane Graph Route With Turn Penalties and Forbidden Maneuvers

Last updated: November 29, 2026

Quick Overview

Given a directed lane graph where each lane segment has a travel cost and certain consecutive segment pairs carry a turn penalty or are forbidden (for example unprotected lefts), find the cheapest route from a start node to a goal node.

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

0

0

0 solved


Given a directed lane graph where each lane segment has a travel cost and certain consecutive segment pairs carry a turn penalty or are forbidden (for example unprotected lefts), find the cheapest route from a start node to a goal node.

A robotaxi route planner often prefers three right turns over one unprotected left, and some maneuvers are simply disallowed for the vehicle's operating domain. The question checks whether you notice that turn costs make plain node-based Dijkstra incorrect, and whether you lift the search state to lane segments.

What the Interviewer Expects
  • Explain why node-state Dijkstra fails when cost depends on the incoming segment
  • Run Dijkstra over segment states (edge-based graph)
  • Skip forbidden transitions and add penalties on transitions
  • Reconstruct the path from parent pointers
  • State complexity in terms of segments and transitions
Key Topics to Cover
Dijkstra
edge-based graph
route planning
path reconstruction
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 add time-of-day dependent costs while keeping the search correct?
  • How would you speed this up for city-scale graphs (A*, contraction hierarchies)?
  • How would you avoid routes through areas outside the operational design domain?
  • How do you handle a goal that is a point partway along a lane segment?
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

segments[id] = (u, v, cost) is a directed lane segment. turn_cost[(a, b)] is the extra cost of driving b immediately after a, with None meaning forbidden. All costs are nonnegative. Return t...

High-Level Design

With node states, Dijkstra settles node X once with the cheapest arrival, but the cheapest arrival may come in on a segment that makes the next turn expensive or forbidden, while a pricier arrival wou...


Submit Your Answer
Markdown supported

Related Questions