Alert incident clustering
An incident-management tool clusters n alerts (0..n-1) that are linked by `edges` `[a, b]` meaning the two alerts are correlated. Two alerts are in the same incident if they are connected directly or transitively. Return a list `label` of length n where `label[i]` is the incident id of alert i. Number incidents 0, 1, 2, ... in the order their lowest-numbered alert first appears (so alert 0 is always in incident 0).
Implement
relabel_components(n: int, edges: list[list[int]]) → list[int]Examples
in
[5,[[0,1],[3,4]]]out[0,0,1,2,2]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 20 min
solution.py
InputExpectedGot
[5,[[0,1],[3,4]]][0,0,1,2,2]not run yetsample