Description Link to heading
1877.minimize-maximum-pair-sum-in-array
Solution Link to heading
Sort the array from smallest to largest, the smallest and largest pair, the next smallest and next largest pair, in that order. The result we need the maximum value of the sum of those pairs.
Code Link to heading
class Solution {
public:
int minPairSum(vector<int>& nums) {
sort(nums.begin(), nums.end());
int res = 0;
for (int i = 0; i < nums.size(); i++) {
res = max(res, nums[i] + nums[nums.size() - 1 -i]);
}
return res;
}
};