Minimize Maximum Pair Sum in Array LeetCode solution in Java

1
class Solution {
2
public int minPairSum(int[] nums) {
3
Arrays.sort(nums);
4

5
int output = Integer.MIN_VALUE;
6

7
// This is greedy, so n/2 pairs must be from start and end and move inwards
8
for (int i = 0, j = nums.length - 1; i < nums.length / 2; i++, j--) {
9
output = Math.max(output, nums[i] + nums[j]);
10
}
11

12
return output;
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0