class Solution:
def groupThePeople(self, groupSizes: list[int]) -> list[list[int]]:
ht: dict[int, list[int]] = {}
for i, s in enumerate(groupSizes):
ht[s] = ht.get(s, [])
ht[s].append(i)
result = []
for s, l in ht.items():
result.extend([l[i : i + s] for i in range(0, len(l), s)])
return result
1282. Group the People Given the Group Size They Belong To - LeetCode
ยท One min read