PythiloMedium · 20 min · Task 14 of 20 · progress kept in this browser

Count connected groups

Nodes are connected by undirected edges. Count the separate groups, where two nodes are in the same group if a path joins them.

count_components(
    [1, 2, 3, 4], [(1, 2), (2, 3)])
# 2: {1, 2, 3} and {4}
Your task

Write count_components(nodes, edges) returning the number of connected groups, using an explicit stack. It must handle a chain of thousands of nodes.

Next: Exact change