Museum Corridor Sweep
The museum’s security team monitors corridors linked by sensors (0 to n-1). During a system upgrade, certain corridor segments are Offline. Your mission in Museum Corridor Sweep is to find the Shortest Path (minimum number of sensor points) to move from a specific start area to an exit while avoiding all offline zones.
The "secret sauce" here is Breadth-First Search (BFS). Since you want the quickest route through the layout, BFS is the gold standard. It explores level by level, ensuring the first time you reach the exit, you've found the shortest possible path. Crucially, you must skip any nodes in the offline_zones list. If no path exists, return -1 correctly. This sweep ensures the guards can respond to alarms instantly, even when the facility's map is partially limited. It’s a practical application of grid or network navigation and a cornerstone of modern security logistics!
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
Rooms 0, 1, and 2 form one connected section; rooms 3 and 4 are separate.
The sweep reaches rooms 2 and 3; the other rooms remain unchecked.
The sweep moves through every room in sequence without revisiting any room.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int calculate_min_workers(int[][] workers, int length) {
Arrays.sort(workers, (a, b) -> a[0] - b[0]);
int res = 0, currentFar = 0, i = 0;
while (currentFar < length) {
int nextFar = currentFar;
while (i < workers.length && workers[i][0] <= currentFar) {
nextFar = Math.max(nextFar, workers[i][1]);
i++;
}
if (nextFar == currentFar) return -1;
res++;
currentFar = nextFar;
}
return res;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
