Mountain Cabin Signal Range
Mountain cabins are linked by suspension bridges. Your mission in Mountain Cabin Signal Range is to find how many unique cabins can receive a signal from a starting origin without crossing any Blocked Bridges. You treat the cabins as nodes and the bridges as edges in a network map.
The "secret sauce" here is Graph Traversal with Edge Filters. Using BFS or DFS, explore every possible path from the start cabin while immediately skipping any bridge in the blocked_bridges list. Duplicate or reversed entries in the data shouldn't change the reachable count. Every accessible cabin is counted once, and the starting point always counts as a recipient. This audit tells the coordinator exactly which parts of the mountain are currently in sync! It’s an essential skill for building logistics or disaster relief routing software under dynamic constraints.
When the task involves connectivity or route cost, build adjacency carefully and guard against revisiting stale states. Use a visited or best-distance structure to avoid repeated work, and ensure unreachable scenarios return the required fallback value instead of partial traversal results.
Examples
Cabins 0, 1, and 2 receive the alert before reaching the blocked bridge between cabins 2 and 3.
Cabin 3 stands alone, so only the origin is counted.
With no blocked bridges, the signal reaches every cabin in the connected component.
Algorithm Flow

Best Answers
class Solution {
public double calculate_min_range(int[][] cabins) {
int n = cabins.length;
if (n <= 1) return 0.0;
double[] minD = new double[n];
Arrays.fill(minD, Double.MAX_VALUE);
minD[0] = 0.0;
boolean[] visited = new boolean[n];
double res = 0.0;
for (int i = 0; i < n; i++) {
int u = -1;
for (int j = 0; j < n; j++) {
if (!visited[j] && (u == -1 || minD[j] < minD[u])) u = j;
}
visited[u] = true;
res = Math.max(res, minD[u]);
for (int v = 0; v < n; v++) {
if (!visited[v]) {
double d = Math.sqrt(Math.pow(cabins[u][0] - cabins[v][0], 2) + Math.pow(cabins[u][1] - cabins[v][1], 2));
minD[v] = Math.min(minD[v], d);
}
}
}
return res;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
