Cheapest Cross Border Shipping Route Within A Delivery Promise
Last updated: November 29, 2026
Quick Overview
Given warehouses and ports as nodes and shipping lanes with a cost and a whole number of transit days, find the minimum cost to move a parcel from a source to a destination such that total transit time is at most D days, or return -1.
Pinduoduo
November 29, 20260
0
0 solved
Given warehouses and ports as nodes and shipping lanes with a cost and a whole number of transit days, find the minimum cost to move a parcel from a source to a destination such that total transit time is at most D days, or return -1.
Temu, PDD Holdings' cross-border marketplace, promises delivery windows to overseas shoppers while keeping logistics costs very low, so routing is a constrained trade-off between price and time. The interviewer looks for recognizing that plain Dijkstra on cost fails, and for a resource-constrained shortest path formulation with a clear complexity argument.
What the Interviewer Expects
- Explains why Dijkstra on cost alone can pick a route that breaks the day limit
- Adds days as a DP dimension: best[node][day]
- Processes days in increasing order, which is valid because every lane takes at least one day
- Returns the minimum over all day counts at the destination
- States O(D * E) time and discusses when D is too large
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
- What if some lanes take zero days (same-city transfers)?
- How would you return the actual route?
- D is in hours and can be 500; how does performance change and what would you prune?
- How would you model per-parcel customs clearance delays that are uncertain?
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, directed lanes (u, v, cost, days) with days >= 1, a source, a destination and a budget D. Minimize cost subject to total days at most D. Cycles are allowed but never help because c...
High-Level Design
Dijkstra on cost alone fails: in the example, the cheapest route (0 to 2 to 3, cost 70) takes 10 days, while with D = 4 the answer is the 200-cost route through node 1. The fix is to expand the state ...