Earliest Arrival Across a Sailing Schedule With Connection Windows

Last updated: November 29, 2026

Quick Overview

Given a list of scheduled sailings (from port, to port, departure time, arrival time), a cargo-ready time at the origin and a minimum connection time for transshipments, find the earliest possible arrival at the destination and the sailings used.

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

0

0

0 solved


Given a list of scheduled sailings (from port, to port, departure time, arrival time), a cargo-ready time at the origin and a minimum connection time for transshipments, find the earliest possible arrival at the destination and the sailings used.

Ocean schedules are timetables, not static graphs, and a quote that promises a connection the cargo cannot make is a broken promise to the shipper. This onsite-style problem checks whether you can adapt Dijkstra to time-dependent edges, argue why it stays correct, and handle connection buffers.

What the Interviewer Expects
  • Model ports as nodes and sailings as timed edges
  • Explain why earliest-arrival Dijkstra is correct when waiting at a port is allowed
  • Apply the connection buffer only at transshipment ports, not at the origin
  • Reconstruct the chosen sailings
  • Discuss sorting departures per port and pruning
Key Topics to Cover
Time-Dependent Shortest Path
Dijkstra
Priority Queue
Scheduling
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 also cap the number of transshipments?
  • Vessels are often late. How would you choose a plan that is robust to a 48 hour delay on the first leg?
  • How would you precompute this for thousands of origin and destination pairs every night?
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

Sailings are (id, from, to, depart, arrive) in hours since some epoch. Cargo is ready at origin at ready_time, so the first sailing must depart at or after that. At any other port, the next depa...

High-Level Design

Arriving earlier at a port is never worse, because you can always wait for the same later sailing. That FIFO property is what makes Dijkstra valid: pop the port with the smallest known arrival, and it...


Submit Your Answer
Markdown supported

Related Questions