Cheapest Shipping Route With Limited Carrier Handoffs

Last updated: November 29, 2026

Quick Overview

Given directed shipping legs (from_hub, to_hub, cost, carrier), a source and a destination, find the minimum total cost route that changes carriers at most K times between consecutive legs, or return -1 if none exists.

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

0

0

0 solved


Given directed shipping legs (from_hub, to_hub, cost, carrier), a source and a destination, find the minimum total cost route that changes carriers at most K times between consecutive legs, or return -1 if none exists.

eBay's shipping programs route packages across partner carriers, and every carrier handoff adds risk of loss and delay. This onsite problem checks whether you can extend Dijkstra with extra state, and whether you notice that plain shortest path on hubs alone gives wrong answers.

What the Interviewer Expects
  • Explain why node-only Dijkstra fails with a handoff budget
  • Define state as (hub, last carrier, handoffs used)
  • Count a handoff only when the carrier changes, not on the first leg
  • Prune states that exceed K
  • Give complexity in terms of states and edges
Key Topics to Cover
Dijkstra
state-space search
weighted graphs
constrained shortest path
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
  • Minimize handoffs first, then cost.
  • Add a per-hub handling delay and a delivery deadline.
  • How would you precompute routes for millions of daily label requests?
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

Legs are directed with non-negative cost. A route is a sequence of legs from src to dst. The first leg has no handoff; each later leg whose carrier differs from the previous leg's carrier uses one...

High-Level Design

With a constraint, the cheapest way to reach a hub is not always the best way to continue: a cheap path that used up all handoffs may be stuck on the wrong carrier. So the state must include what affe...


Submit Your Answer
Markdown supported