30 Days of Code [Day 19]
QUESTION : 406. Queue Reconstruction by Height
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define fv(V) for( auto &it : V )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
fastio;
vector<vi> res;
res.reserve(people.size());
sort(all(people), [](vi& v1, vi& v2){
if(v1[0] == v2[0])
return v1[1] < v2[1];
return v1[0] > v2[0];
});
fv(people){
res.insert(res.begin()+it[1], it);
}
return res;
}
};