Search⌘ K
AI Features

Solution: Divide Nodes Into the Maximum Number of Groups

C# solution for the Divide Nodes Into the Maximum Number of Groups problem using the Graphs pattern.

We'll cover the following...

Statement

You are given an undirected graph with n nodes labeled from 11 to n, and an edge list edges where each edges[i] connects two distinct nodes.

You want to partition all nodes into the maximum possible number of non empty groups, numbered consecutively from 11 to k, such that for every edge connecting nodes u and v, the group indices of u and v differ by exactly 11.

Return the maximum valid k. If no such grouping exists, return 1-1.

Constraints:

  • 11 \leq n ...