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
November 29, 20260
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
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 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 ProblemsSample 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...