Cheapest Shared Network Carrying Two Feeds Into One Region
Last updated: November 29, 2026
Quick Overview
Given a directed weighted network, choose a set of edges of minimum total weight such that both source s1 and source s2 can reach destination dest using only chosen edges. Return that weight or -1.
Meta
November 29, 20260
0
0 solved
Given a directed weighted network, choose a set of edges of minimum total weight such that both source s1 and source s2 can reach destination dest using only chosen edges. Return that weight or -1.
A Meta onsite problem about combining shortest path trees. It can be framed as two upstream data centers both replicating into one region. Interviewers want the insight that optimal routes merge at one node and then share the rest of the way, which reduces the problem to three Dijkstra runs.
What the Interviewer Expects
- Argue that an optimal subgraph is two paths that merge at a meeting node and then share one path to dest
- Run Dijkstra from s1, from s2, and from dest on the reversed graph
- Minimize d1[m] + d2[m] + dd[m] over all meeting nodes m
- Handle unreachable combinations
- Explain why reversing edges gives distances to dest
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
- Why can the two paths not benefit from merging, splitting and merging again?
- How would this generalize to three sources?
- What if edges were undirected?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
nup to 10^5, directed edges(u, v, w)with positive weights.- Find the minimum total weight of an edge set in which both sources reach
dest....
High-Level Design
Once the two routes share a node m, the cheapest continuation is the single shortest path from m to dest, used by both. Before m, each source takes its own shortest path to m. Any optimal su...