-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1282.cpp
More file actions
32 lines (27 loc) · 907 Bytes
/
1282.cpp
File metadata and controls
32 lines (27 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
unordered_map<int, vector<int>> mp;
for(int i = 0; i < groupSizes.size(); ++i)
{
mp[groupSizes[i]].push_back(i);
}
vector<vector<int>> ans;
for(auto it: mp)
{
int key = it.first; //limit of a group
auto personsList = it.second; //iterator to list of persons
vector<int> temp; //temporary array to store the group
for(int i = 0; i < personsList.size(); ++i)
{
temp.push_back(personsList[i]);
if(temp.size() == key)
{
ans.push_back(temp);
temp.clear();
}
}
}
return ans;
}
};