Cheapest Cross-Region Transfer Using One Free Link Voucher

Last updated: November 29, 2026

Quick Overview

Given directed links between data centers with transfer costs, find the cheapest route from source to destination when you may waive the cost of exactly one link of your choice (or none).

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given directed links between data centers with transfer costs, find the cheapest route from source to destination when you may waive the cost of exactly one link of your choice (or none).

ByteDance moves petabytes between regions for model training and video backup, and planning sometimes has one link with spare prepaid capacity. The question checks whether you can extend Dijkstra with a state dimension instead of trying every link to waive, which would be E times more expensive.

What the Interviewer Expects
  • Model state as (node, voucher_used)
  • Run Dijkstra on the layered graph
  • Relax both paying and free transitions
  • Return the best of both layers at the destination
  • Compare with the naive E-times-Dijkstra approach
Key Topics to Cover
Dijkstra
state-space search
layered graph
shortest paths
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
  • Generalize to K vouchers. What is the complexity?
  • What if a voucher halves the cost instead of waiving it?
  • Solve it with two Dijkstra runs (forward from source, backward from destination) and compare.
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 nodes, directed links (u, v, cost) with non-negative costs, src, dst. Output: minimum total cost using at most one free link, or -1 if unreachable....

High-Level Design

Duplicate each node into two layers: layer 0 means the voucher is unused, layer 1 means used. From (u, 0) you can go to (v, 0) paying c or to (v, 1) paying 0. From (u, 1) you can only pay. R...


Submit Your Answer
Markdown supported