Code Room
CodingEasycod-g744
Subject DfsLevel Entry–Mid~20 minCommon in Algorithms & data structures interviewsIndustries Software development, IT services

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.