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
November 29, 20260
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
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
- 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 ProblemsSample 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...