Cheapest Air Cargo Route With at Most K Intermediate Stops
Last updated: November 29, 2026
Quick Overview
Amazon Air cargo can move between airports on flights with known costs. Find the cheapest cost from a source airport to a destination using at most k intermediate stops, or return -1 if impossible.
Amazon
November 29, 20260
0
0 solved
Amazon Air cargo can move between airports on flights with known costs. Find the cheapest cost from a source airport to a destination using at most k intermediate stops, or return -1 if impossible.
This mirrors Amazon Air network planning, where extra stops add handling risk. Interviewers check that you see why plain Dijkstra is wrong with a hop limit and that you can run a bounded Bellman-Ford or a state-expanded search correctly.
What the Interviewer Expects
- Explain why greedy Dijkstra on cost alone can discard a cheaper path that uses fewer hops
- Use Bellman-Ford relaxation for k + 1 rounds
- Copy the previous round's distances so each round adds at most one edge
- Return -1 when the destination stays unreachable
- Give O(k * E) complexity
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 also return the actual route?
- What if the objective is cheapest cost with a tie-break on fewest stops?
- How would you handle thousands of queries on the same flight network?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: n airports, flights (u, v, cost) with non-negative costs, src, dst, and k. A route with at most k intermediate stops uses at most k + 1 flights. Output the minimum total cost or -1....
High-Level Design
Bellman-Ford with a round limit. cost[i] is the cheapest cost to reach airport i using at most r flights after round r. Each round starts from a copy of the previous array and relaxes every flight u...