Fastest Image Replication Across Regions with One Free Link
Last updated: November 29, 2026
Quick Overview
Regions are connected by bidirectional links with transfer times. You may use exactly one link for free once (a reserved fast lane). Find the minimum time to replicate a Pin image from a source region to a destination region.
0
0
0 solved
Regions are connected by bidirectional links with transfer times. You may use exactly one link for free once (a reserved fast lane). Find the minimum time to replicate a Pin image from a source region to a destination region.
Pinterest replicates image assets across data centers and CDN origins, and capacity teams sometimes reserve a premium link for urgent transfers. The onsite question tests whether you can extend Dijkstra with a state dimension rather than trying every edge as the free one.
What the Interviewer Expects
- Recognizes the layered graph idea: state is (node, free_used)
- Runs Dijkstra on 2n states with lazy deletion of stale heap entries
- Adds a zero-cost transition that flips the flag
- Returns early when the destination is popped
- Compares with the naive approach of rerunning Dijkstra per edge
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 free links.
- What if the free link instead halves the transfer time?
- How would you handle links whose speed changes during the day?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- n regions 0..n-1, links (u, v, ms) non-negative, undirected.
- At most one link may cost 0 (using none is allowed, though with non-negative weights it never helps to skip it).
- Output: minimum tota...
High-Level Design
Duplicate the graph into two layers: layer 0 means the free link is unused, layer 1 means it is spent. Every real edge exists inside each layer with its weight, and every edge also connects layer 0 to...