Group the People Given the Group Size They Belong To LeetCode solution in JavaScript

1
/**
2
* @param {number[]} groupSizes
3
* @return {number[][]}
4
*/
5
var groupThePeople = function (groupSizes) {
6
let indices = [],
7
result = [];
8
groupSizes.forEach((x, idx) => {
9
if (indices[x]) indices[x].push(idx);
10
else indices[x] = [idx];
11
if (indices[x].length === x) {
12
result.push(indices[x]);
13
indices[x] = undefined;
14
}
15
});
16
return result;
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0