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
Coding & Algorithms
Software Engineer
Pinduoduo
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
constrained shortest path
dynamic programming
graphs
Bellman-Ford
logistics
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
  • 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions