Earliest Package Arrival Through Scheduled Carrier Hub Legs

Last updated: November 29, 2026

Quick Overview

Shipping between hubs happens only on scheduled legs (from hub, to hub, departure time, arrival time), and a package needs a fixed transfer time at every intermediate hub. Given the package's ready time at the origin, return the earliest time it can reach the destination, or -1 if it cannot.

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

0

0

0 solved


Shipping between hubs happens only on scheduled legs (from hub, to hub, departure time, arrival time), and a package needs a fixed transfer time at every intermediate hub. Given the package's ready time at the origin, return the earliest time it can reach the destination, or -1 if it cannot.

Whatnot buyers care about how fast a won item ships, and estimating delivery dates means reasoning over carrier schedules rather than plain distances. The interviewer wants to see Dijkstra adapted to time-dependent edges and a correctness argument for why it still works.

What the Interviewer Expects
  • Model hubs as nodes and legs as time-windowed edges
  • Use earliest arrival time as the Dijkstra key
  • Only take legs departing after arrival plus transfer time
  • Skip the transfer time at the origin
  • Argue correctness from the FIFO property of schedules
Key Topics to Cover
shortest paths
Dijkstra
time-dependent graphs
binary search
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 return the itinerary as well as the arrival time?
  • How would you minimize the number of transfers among routes that arrive equally early?
  • Legs can be delayed. How would you produce a delivery estimate with a confidence range?
  • When is the connection scan algorithm a better choice?
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: legs (u, v, depart, arrive), src, dst, ready_time, and transfer. At the origin a package can board any leg with depart >= ready_time. At any other hub reached at time t, it can boar...

High-Level Design

Run Dijkstra where the distance to a hub is the earliest time the package can be there. For each hub, keep its outgoing legs sorted by departure so the boardable ones are a suffix found with binary se...


Submit Your Answer
Markdown supported

Related Questions