Code Room
CodingMedium
Question
You start with n isolated nodes labeled 0..n-1 and process a list of undirected merge operations [u, v]. After each operation, report the current number of connected components. Return a list of length len(ops) giving the component count after each merge in order. Merging two already-connected nodes leaves the count unchanged.
Implement
components_after_merges(n: int, ops: list[list[int]]) → list[int]Examples
in
[5,[[0,1],[2,3],[1,3],[0,2]]]out[4,3,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.
Learn the concepts
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.