Cheapest Cross-Region Data Transfer Within K Intermediate Hops
Last updated: November 29, 2026
Quick Overview
Given directed transfer links between IBM Cloud regions with egress costs, find the cheapest cost to move a dataset from a source region to a destination using at most k intermediate regions, or -1 if impossible.
IBM
November 29, 20260
0
0 solved
Given directed transfer links between IBM Cloud regions with egress costs, find the cheapest cost to move a dataset from a source region to a destination using at most k intermediate regions, or -1 if impossible.
IBM Cloud bills cross-region egress, and data teams route replication through intermediate regions to save cost while capping latency with a hop limit. This constrained shortest-path question appears in harder IBM onsites to test whether you know why plain Dijkstra fails and how to bound relaxations by hop count.
What the Interviewer Expects
- Explain why plain Dijkstra on cost alone can return paths with too many hops
- Use Bellman-Ford limited to k + 1 rounds
- Copy the distance array each round so one round adds one edge
- Return -1 when unreachable
- Discuss Dijkstra over (node, hops) states as an alternative
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 actual route?
- What if both cost and latency must be under limits?
- How would the approach change with thousands of regions and frequent queries?
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 regions labeled 0..n-1, links as (u, v, cost) directed edges, src, dst, and k. A path may use at most k + 1 edges. Output the minimum total cost or -1. Costs are non-negative....
High-Level Design
Run k + 1 rounds of edge relaxation. In each round, compute new distances from a snapshot of the previous round's distances, so a round can add at most one edge to any path. After round r, dist[v] i...