function groupThePeople(groupSizes: number[]): number[][] {
const buckets: { [key: number]: number[] } = Object.create(null);
for (let i = 0; i < groupSizes.length; ++i) {
const bucket: number[] = buckets[groupSizes[i]] || [];
bucket.push(i);
buckets[groupSizes[i]] = bucket;
}
const results: number[][] = [];
for (const index in buckets) {
const bucket: number[] = buckets[index];
for (let end = +index; end <= bucket.length; end += +index) {
results.push(bucket.slice(end - +index, end));
}
}
return results;
};