#3659
Partition Array Into K-Distinct Groups
medium · 47% accepted · 113 likes · top 32%
array · hash table · counting
Description
You are given an integer array nums and an integer k.
Your task is to determine whether it is possible to partition all elements of nums into one or more groups such that:
- Each group contains exactly k elements.
- All elements in each group are distinct.
- Each element in nums must be assigned to exactly one group.
Return true if such a partition is possible, otherwise return false.
Solution