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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
Dijkstra
time-dependent shortest path
FIFO property
priority queue
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
  • 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 Problems
Sample Answer
Requirements
  • Input: edges list of (u, v, first, period, duration), start s, start time t0, destination d.
  • 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) ...


Submit Your Answer
Markdown supported