Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Monday, Dec 7.Claim the deal

You are given groups, an array of disjoint, non-empty groups of node IDs. The nodes in each group are already connected.

Add undirected edges between nodes in different groups so that all groups become connected using the minimum possible number of new edges. If there are K groups, return exactly K - 1 edges. After treating each group as one vertex, the selected edges must connect all groups without forming a cycle.

Stdout
-