Earliest Car Arrival Across Rail Yards With Dwell Times
Last updated: November 29, 2026
Quick Overview
Given directed track segments between yards with travel hours, and a dwell time charged whenever a car leaves an intermediate yard, return the minimum total hours for a car to go from an origin yard to a destination yard, or -1 if it cannot.
Bnsf
November 29, 20260
0
0 solved
Given directed track segments between yards with travel hours, and a dwell time charged whenever a car leaves an intermediate yard, return the minimum total hours for a car to go from an origin yard to a destination yard, or -1 if it cannot.
An onsite coding problem in the style of BNSF's trip planning work, where a car's total transit is dominated by time sitting in yards, not time moving. The interviewer checks that you fold node costs into Dijkstra correctly (not at the origin, not at the destination) and reason about why greedy shortest-distance routing is wrong here.
What the Interviewer Expects
- Recognizes a shortest path problem with node weights
- Charges dwell on departure from intermediate yards only
- Implements Dijkstra with a heap and stale-entry skipping
- Returns early when the destination is popped
- States complexity and handles unreachable and same-yard cases
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 handle trains that only depart at scheduled times, so a car must wait for the next train?
- What if dwell depends on the inbound and outbound direction through a yard?
- How would you return the actual route, not just the time?
- What if some yards are embargoed for certain commodities?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: edges as (u, v, hours), a dwell map of yard to hours, src, and dst. A car that passes through yard Y pays dwell[Y] once before it leaves Y. The origin is not charged (the car is re...
High-Level Design
Node weights can be pushed onto outgoing edges: leaving u costs dwell[u] + w. That keeps the graph non-negative, so Dijkstra applies. Charging on departure rather than arrival naturally excludes the...