Cheapest Cross-Border Shipping Route With Limited Customs Crossings
Last updated: November 29, 2026
Quick Overview
Given a directed network of shipping legs between warehouses, hubs and delivery stations, each with a cost and a flag for whether it crosses a customs border, find the cheapest route from a seller warehouse to a destination using at most K border crossings, and return the route.
Temu
November 29, 20260
0
0 solved
Given a directed network of shipping legs between warehouses, hubs and delivery stations, each with a cost and a flag for whether it crosses a customs border, find the cheapest route from a seller warehouse to a destination using at most K border crossings, and return the route.
Temu's logistics chain moves parcels from factory regions through consolidation hubs and transit countries to local carriers, and every customs crossing adds delay and clearance risk. Onsite, this tests whether you can extend Dijkstra with a resource dimension and reconstruct the path correctly.
What the Interviewer Expects
- Recognize that plain Dijkstra is wrong because a cheaper path may use too many crossings
- Model state as (node, crossings used)
- Keep a parent pointer per state to rebuild the route
- Stop at the first time the destination is popped
- State complexity in terms of V, E and K
- Discuss what to do when costs are multi-objective (money and days)
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 minimize cost subject to a delivery-time limit instead of a crossing count?
- What if some legs have capacity limits per day?
- How would you precompute routes for millions of parcels per day?
- Why is Bellman-Ford with K rounds not the same as this problem?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Nodes 0..n-1, legs (u, v, cost, crosses_border) with non-negative cost. Return (cost, path) for the cheapest src to dst route with at most max_border crossings, or (-1, []) if none exists....
High-Level Design
A greedy shortest path can pick a cheap route that crosses three borders when only two are allowed, and once a node is settled Dijkstra would never revisit it. Expanding the state to (node, used) fi...