BudiBadu Logo

Skyway Signal Cluster

Array Easy 0 views
Like6

The aerial transit authority manages floating decks (0 to n-1) linked by bidirectional skyway segments. When a broadcast starts at one deck, it spreads through every segment to neighboring decks. Your goal in Skyway Signal Cluster is to quantify the maximum reach of the signal broadcast. How many unique decks will receive the message once it spreads as far as possible?

The "secret sauce" here is Graph Connectivity (BFS/DFS). Treat the decks as nodes and segments as edges. Starting from the start deck, traverse the network to find every reachable point. Disconnected groups remain silent, and the starting point always counts as one recipient. Data irregularities like duplicate connectors or self-loops shouldn't change the count. Return the total size of this connected cluster as an integer. This helps the authority measure broadcast coverage and plan emergency staffing across the skyway lanes with precision!

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

Example 1
Input
n = 4, connectors = [], start = 1
Output
1
Explanation

With no connectors, the broadcast remains at the starting deck.

Example 2
Input
n = 5, connectors = [[0,1],[1,2],[2,3],[3,4]], start = 2
Output
5
Explanation

Every deck is connected through the chain, so the broadcast covers all decks.

Example 3
Input
n = 6, connectors = [[0,1],[2,3],[3,4],[4,2]], start = 3
Output
3
Explanation

The cluster includes decks 2, 3, and 4; the other decks are unreachable.

Algorithm Flow

Recommendation Algorithm Flow for Skyway Signal Cluster - Budibadu
Recommendation Algorithm Flow for Skyway Signal Cluster - Budibadu

Best Answers

java
import java.util.*;
class Solution {
    public List<List<String>> group_signal_patterns(String[] patterns) {
        Map<String, List<String>> res = new HashMap<>();
        for (String p : patterns) {
            char[] chars = p.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            res.computeIfAbsent(key, x -> new ArrayList<>()).add(p);
        }
        List<List<String>> values = new ArrayList<>(res.values());
        values.sort(Comparator.comparingInt(List::size));
        return values;
    }
}