Cheapest Shipping Route Using Up to K Half-Price Coupons
Last updated: November 29, 2026
Quick Overview
Given a directed graph of shipping legs with costs, find the cheapest way from src to dst when you may apply up to k coupons, each halving the cost of one leg (rounded down). Return -1 if dst is unreachable.
Meta
November 29, 20260
0
0 solved
Given a directed graph of shipping legs with costs, find the cheapest way from src to dst when you may apply up to k coupons, each halving the cost of one leg (rounded down). Return -1 if dst is unreachable.
A Meta phone screen variant of Dijkstra on a layered graph, framed around routing Marketplace shipments with promotional credits. The interviewer wants to see state expansion to (node, coupons used) and an argument for why Dijkstra still applies on that product graph.
What the Interviewer Expects
- Expand the state to (node, coupons used)
- Relax two transitions per edge: full price and coupon
- Explain the layered graph view with k + 1 copies of every node
- Return as soon as the destination is popped in any layer
- Discuss complexity in terms of k
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 each coupon could only be used on specific legs?
- How would you handle coupons that subtract a fixed amount instead of halving?
- Could you solve it with a single-layer Dijkstra if k were huge?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
nup to 10^4 nodes, directed legs(u, v, cost)with non-negative integer cost,0 <= k <= 10.- Each coupon applies to one leg and halves its cost with floor division.
- Return the minimum tota...
High-Level Design
Build an implicit graph with k + 1 layers: node (v, j) means we are at v having used j coupons. A leg u -> v gives edges (u, j) -> (v, j) at full cost and (u, j) -> (v, j + 1) at half co...