ans to store the final groups.szToGroup to map group sizes to lists of indices.groupSizes array with index i:
a. Append index i to the list szToGroup[groupSizes[i]].
b. If the size of szToGroup[groupSizes[i]] equals groupSizes[i], append the list to ans and reset szToGroup[groupSizes[i]] to an empty list.ans containing all the groups.