Imagine you're organizing a team-building event where n people need to be divided into groups based on their preferences. Each person has a unique ID from 0 to n-1, and they've told you exactly what group size they want to be in.
You're given an array groupSizes where groupSizes[i] represents the desired group size for person i. For example, if groupSizes[1] = 3, then person 1 wants to be in a group of exactly 3 people.
Your goal: Create groups where every person gets their desired group size. Each person must appear in exactly one group, and the actual size of each group must match what its members requested.
Since multiple valid groupings might exist, you can return any valid solution. The problem guarantees that at least one solution always exists.
Input & Output
Constraints
- 1 โค groupSizes.length โค 500
- 1 โค groupSizes[i] โค groupSizes.length
- Important: It's guaranteed that there will be at least one valid solution