Imagine looking after a city full of routes, signals, or stops. In City Signal Span, you are trying to work toward the right number by following one clear idea.
Calculate emergency broadcast signal span A good way to think about it is to first understand what goes in, then what rule you must follow, and finally what shape the answer should have.
For example, if the input is n = 4, roads = [[0,1],[1,2],[2,3]], start = 0, the answer is 4. The signal travels along every road and covers all four intersections. Another example is n = 6, roads = [[0,1],[1,2],[2,0],[3,4]], start = 5, which gives 1. Intersection 5 is isolated, so only the starting point receives the broadcast.
This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.
One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.
Example Input & Output
The signal travels along every road and covers all four intersections.
Intersection 5 is isolated, so only the starting point receives the broadcast.
Intersections 0, 1, and 2 share a chain of roads, while 3 and 4 are separate.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int city_signal_span(int n, int[][] roads, int start) {
List<List<Integer>> adj = new ArrayList<>();
for (int i = 0; i < n; i++) adj.add(new ArrayList<>());
for (int[] road : roads) {
adj.get(road[0]).add(road[1]);
adj.get(road[1]).add(road[0]);
}
Set<Integer> visited = new HashSet<>();
visited.add(start);
Queue<Integer> queue = new LinkedList<>();
queue.add(start);
while (!queue.isEmpty()) {
int curr = queue.poll();
for (int neighbor : adj.get(curr)) {
if (!visited.contains(neighbor)) {
visited.add(neighbor);
queue.add(neighbor);
}
}
}
return visited.size();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
