class Solution {
public:
vector<vector<int>> divideArray(vector<int>& nums, int k) {
// sort array from small to large
// divide into 3 part
// iterate and check if part[0] - part[2] is bigger than k
// if yes, return empty vector
// if no, assign part[0], part[1], part[2] to one vector
sort(nums.begin(), nums.end());
vector<vector<int>> ans = {nums.size()/3, vector<int>{}};
for(int i = 0; i < nums.size(); i+=3){
if((nums[i+2] - nums[i]) <= k) {
ans[i/3] = {nums[i], nums[i+1], nums[i+2]};
} else {
return vector<vector<int>>{};
}
}
return ans;
}
};