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.

Statement

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

You want to partition all vertices into an ordered sequence of non empty groups, numbered from 11 to k, such that for every edge connecting vertices u and v, the group indices of u and v differ by exactly 11.

Return the maximum possible value of k over all valid groupings. If no valid grouping exists, return 1-1.

Note: ...