Skip to interview prep
Apexed
Problem list141 / 143

141. Track Network Splits During Link Outages

HardDisjoint sets

Nodes 0 to count - 1 are initially connected by all the supplied undirected links. Each outage contains the index of a link to remove.

Return the number of connected components after each outage, counting isolated nodes. Removing an already down link changes nothing. Two links with the same endpoints are separate entries.

Example 1

Input: count = 4, links = [[0,1],[1,2],[0,2],[2,3]], outages = [3,0,1,1,2]
Output: [2,2,3,3,4]

Example 2

Input: count = 2, links = [[0,1],[0,1]], outages = [1,1,0]
Output: [1,1,2]

Constraints

  • 0 ≤ count ≤ 100,000. Links and outage lists each contain at most 100,000 entries.
  • Link endpoints and outage indexes are valid. Self-links are allowed.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Track Network Splits During Link Outages — coding interview practice — Apexed