There are n people&nbsp;that are split into some unknown number of groups. Each person is labeled with a&nbsp;unique ID&nbsp;from&nbsp;0&nbsp;to&nbsp;n - 1.

You are given an integer array&nbsp;groupSizes, where groupSizes[i]&nbsp;is the size of the group that person&nbsp;i&nbsp;is in. For example, if&nbsp;groupSizes[1] = 3, then&nbsp;person&nbsp;1&nbsp;must be in a&nbsp;group of size&nbsp;3.

Return&nbsp;a list of groups&nbsp;such that&nbsp;each person&nbsp;i&nbsp;is in a group of size&nbsp;groupSizes[i].

Each person should&nbsp;appear in&nbsp;exactly one group,&nbsp;and every person must be in a group. If there are&nbsp;multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.

&nbsp;
Example 1:

Input: groupSizes = [3,3,3,3,3,1,3]
Output: [[5],[0,1,2],[3,4,6]]
Explanation: 
The first group is [5]. The size is 1, and groupSizes[5] = 1.
The second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.
The third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.
Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].


Example 2:

Input: groupSizes = [2,1,3,3,3,2]
Output: [[1],[0,5],[2,3,4]]


&nbsp;
Constraints:


	groupSizes.length == n
	1 &lt;= n&nbsp;&lt;= 500
	1 &lt;=&nbsp;groupSizes[i] &lt;= n


class Solution(object):
    def groupThePeople(self, groupSizes):
        """
        :type groupSizes: List[int]
        :rtype: List[List[int]]
        """
        dict_group={}
        for i in range(len(groupSizes)):
            if groupSizes[i] not in dict_group:
                dict_group[groupSizes[i]]=[i]
            else:
                dict_group[groupSizes[i]].append(i)
        return_list=[]
        for i in dict_group:
            num_list=dict_group[i]
            for j in range(0,len(num_list),i):
                return_list.append(num_list[j:j+i])
        return return_list
class Solution {
    public List<List<Integer>> groupThePeople(int[] groupSizes) {

        List<List<Integer>> temp = new ArrayList<List<Integer>>();
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        for(int i = 0; i<groupSizes.length; i++){
            int k = groupSizes[i];
            boolean flag = true;
            for(int j = 0; j<temp.size(); j++){
                // If there is a list of reqired group size and it is filled lesser than we can put element in that one
                if(k == temp.get(j).get(0) && k >temp.get(j).get(1)){
                    result.get(j).add(i);
                    temp.get(j).set(1,temp.get(j).get(1)+1);
                    flag=false;
                    break;
                }
            }
            if(flag){
                // comment 1
                // We create a list with index and put it to result
                List<Integer> res = new ArrayList();
                res.add(i);
                result.add(res);
                // comment 2
                // we create a new list recording max value can stored and currently filled
                List<Integer> tempRes = new ArrayList();
                tempRes.add(k);
                tempRes.add(1);
                temp.add(tempRes);
            }
        }
        return result;
    }
}
class Solution {
public:
    vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
        vector<vector<int>>ans;
        unordered_map<int,vector<int>> store;
        
        for(int i=0;i<groupSizes.size();i++){
            if(store[groupSizes[i]].size()==groupSizes[i]){
               ans.push_back(store[groupSizes[i]]) ;
                store[groupSizes[i]].clear();
                }
            store[groupSizes[i]].push_back(i);}
        
        for(auto &x:store){
            ans.push_back(x.second);}
        return ans;     
    }
};
/**
 * @param {number[]} groupSizes
 * @return {number[][]}
 */
var groupThePeople = function(groupSizes) {
    let indices = [], result = [];
    groupSizes.forEach((x, idx) => {
        if (indices[x]) indices[x].push(idx);
        else indices[x] = [idx];
        if (indices[x].length === x) {
            result.push(indices[x]);
            indices[x] = undefined;
        }
    });
    return result;
};
Group the People Given the Group Size They Belong To