Earliest Arrival Time Using Scheduled Ferry and Shuttle Departures
Last updated: November 29, 2026
Quick Overview
Edges between stops depart periodically: each edge (u, v, first, period, duration) leaves u at times first, first + period, and so on, and arrives duration later; starting at stop s at time t0, return the earliest arrival time at stop d, or -1.
Uber
November 29, 20260
0
0 solved
Edges between stops depart periodically: each edge (u, v, first, period, duration) leaves u at times first, first + period, and so on, and arrives duration later; starting at stop s at time t0, return the earliest arrival time at stop d, or -1.
Uber partners with transit and shuttle operators, and itineraries that include scheduled legs need time-dependent routing. The onsite interviewer checks that you adapt Dijkstra to compute edge cost from the current arrival time and that you can argue why it still works (the FIFO property).
What the Interviewer Expects
- Model arrival time as the Dijkstra key
- Compute the next departure at or after the current time
- Explain the FIFO property that keeps Dijkstra correct
- Skip stale heap entries
- Analyze O(E log V)
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
- What if waiting at some stops is not allowed after midnight?
- How would you return the itinerary, not just the time?
- Why might a schedule-based algorithm like CSA (connection scan) be faster for transit timetables?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
edgeslist of(u, v, first, period, duration), starts, start timet0, destinationd. - Riders can wait at stops for free.
- Output: earliest possible arrival time at
d, or -1....
High-Level Design
Run Dijkstra where the label of a node is the earliest arrival time. Relaxing edge (u, v) from arrival time t uses the next departure dep = first if t <= first, else `first + ceil((t - first) ...