Cheapest Freight Route Through Consolidation Hubs Under a Deadline
Last updated: November 29, 2026
Quick Overview
Given a directed network of freight legs between a supplier, consolidation hubs and a customer region, each leg with a cost and a transit time in days, find the cheapest path from source to destination whose total transit time does not exceed a deadline.
Wayfair
November 29, 20260
0
0 solved
Given a directed network of freight legs between a supplier, consolidation hubs and a customer region, each leg with a cost and a transit time in days, find the cheapest path from source to destination whose total transit time does not exceed a deadline.
Bulky furniture is expensive to move, and Wayfair's CastleGate network consolidates supplier freight at hubs before line-haul and last-mile delivery, trading cost against speed. The interviewer wants to see that you recognise plain Dijkstra fails with a second constraint, and can model state as (node, days used) with sound dominance pruning.
What the Interviewer Expects
- Shows why shortest-by-cost Dijkstra alone can violate the deadline
- Models search state as node plus days used
- Prunes dominated labels (higher cost and not faster)
- Returns the path, not just the cost
- Gives complexity in terms of the deadline for integer 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 return the full Pareto frontier of cost versus days so the product page can offer standard and expedited options?
- Legs depart only on certain weekdays. How does the state change?
- Transit times are random. How would you find the cheapest route that meets the deadline with 95% probability?
- How would you precompute this for millions of supplier to ZIP pairs nightly?
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: supplier, hubs, customer region. Legs: (u, v, cost, days) with non-negative integers. Return the minimum cost and a path with total days at most max_days, or None. This is the resource-cons...
High-Level Design
Run Dijkstra on labels (cost, days, node, path) ordered by cost. When a label for node v is popped, every later label for v is at least as expensive, so it is only worth expanding if it uses **stric...