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

0

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
shortest path
Bellman-Ford
hop-constrained paths
weighted graphs
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions