Algorithm · C3.ai · Easy
You are working with an undirected graph that has n nodes, numbered 0 through n-1. Its connections are described by edges, a 2D array in which every entry is a pair [u, v] meaning nodes u and v are joined by an edge. A group is a connected component: a maximal set of nodes in which every node can reach every other node by following edges. Write a function that finds every group in the graph and returns an array of integers, where each integer is the number of nodes in one…