BudiBadu Logo
00:00

Harbor Signal Expansion Test

Graph Easy 0 views

The coastal operations bureau coordinates lighthouses around a harbor to broadcast illumination patterns before each nightly fishing launch. Every lighthouse carries an identifier from 0 to n - 1, and engineers map each bidirectional cable that allows signals to hop between towers. When technicians activate a pattern at one lighthouse, the signal travels through connected cables and keeps spreading from every newly activated tower. Individual lighthouses may be offline for maintenance, blocking the signal from entering that tower or using its cables.

Build a function that accepts the lighthouse count n, a list of cables links, the starting lighthouse start, and a set maintenance describing offline towers. Each cable is represented by [u, v], allowing traffic between towers u and v if both are online. The list can contain duplicate entries, reversed orientations, or self-links from older schematics. The starting tower always operates, but no other offline tower can transmit or receive the signal. Treat duplicates as a single connection and continue exploring until no additional online tower can be reached.

The function should return how many lighthouses participate in the broadcast, including the starting tower. Offline towers never increase the total even if alternative paths exist. If start has no usable cables, the result is 1. In a fully online harbor, the answer equals the size of the connected Region that includes start. Return the count as an integer.

Example 1:

Input: n = 6, links = [[0,1],[1,2],[2,3],[3,4],[4,5]], start = 0, maintenance = [3]
Output: 4
Explanation: Towers 0, 1, 2, and 5 remain online; cable through tower 3 prevents reaching tower 4.

Example 2:

Input: n = 5, links = [[0,1],[1,2],[2,3],[3,4]], start = 3, maintenance = []
Output: 5
Explanation: All towers are online, so the signal covers every lighthouse.

Example 3:

Input: n = 4, links = [[0,1],[1,2]], start = 2, maintenance = [0,1]
Output: 1
Explanation: Maintenance disables the only connecting cables, so the broadcast stays at the starting lighthouse.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Harbor Signal Expansion Test

Graph Easy 0 views

The coastal operations bureau coordinates lighthouses around a harbor to broadcast illumination patterns before each nightly fishing launch. Every lighthouse carries an identifier from 0 to n - 1, and engineers map each bidirectional cable that allows signals to hop between towers. When technicians activate a pattern at one lighthouse, the signal travels through connected cables and keeps spreading from every newly activated tower. Individual lighthouses may be offline for maintenance, blocking the signal from entering that tower or using its cables.

Build a function that accepts the lighthouse count n, a list of cables links, the starting lighthouse start, and a set maintenance describing offline towers. Each cable is represented by [u, v], allowing traffic between towers u and v if both are online. The list can contain duplicate entries, reversed orientations, or self-links from older schematics. The starting tower always operates, but no other offline tower can transmit or receive the signal. Treat duplicates as a single connection and continue exploring until no additional online tower can be reached.

The function should return how many lighthouses participate in the broadcast, including the starting tower. Offline towers never increase the total even if alternative paths exist. If start has no usable cables, the result is 1. In a fully online harbor, the answer equals the size of the connected Region that includes start. Return the count as an integer.

Example 1:

Input: n = 6, links = [[0,1],[1,2],[2,3],[3,4],[4,5]], start = 0, maintenance = [3]
Output: 4
Explanation: Towers 0, 1, 2, and 5 remain online; cable through tower 3 prevents reaching tower 4.

Example 2:

Input: n = 5, links = [[0,1],[1,2],[2,3],[3,4]], start = 3, maintenance = []
Output: 5
Explanation: All towers are online, so the signal covers every lighthouse.

Example 3:

Input: n = 4, links = [[0,1],[1,2]], start = 2, maintenance = [0,1]
Output: 1
Explanation: Maintenance disables the only connecting cables, so the broadcast stays at the starting lighthouse.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.