[AlgoExpert] Task Asssignment

Task Asssignment

  • Time : O(nlogn)
  • Space : O(n)
1
2
3
4
5
6
7
8
9
10
11
12
13
vector<vector<int>> taskAssignment(int k, vector<int> tasks) {
vector<pair<int,int>> vpi;
for(int i = 0; i < 2*k; i++) {
vpi.push_back({tasks[i],i});
}
sort(begin(vpi),end(vpi));
vector<vector<int>> res;

for(int i = 0, j = 2*k-1; i < k; i++,j--) {
res.push_back({vpi[i].second, vpi[j].second});
}
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/05/16/PS/AlgoExpert/task-assignment/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.