1877. Minimize Maximum Pair Sum in Array Medium

@problem@discussion
#Array#Two Pointers#Greedy#Sorting



1/**
2 * [1877] Minimize Maximum Pair Sum in Array
3 *
4 * The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.
5 * 
6 * 
7 * 	For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.
8 * 
9 * 
10 * Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:
11 * 
12 * 
13 * 	Each element of nums is in exactly one pair, and
14 * 	The maximum pair sum is minimized.
15 * 
16 * 
17 * Return the minimized maximum pair sum after optimally pairing up the elements.
18 * 
19 *  
20 * Example 1:
21 * 
22 * 
23 * Input: nums = [3,5,2,3]
24 * Output: 7
25 * Explanation: The elements can be paired up into pairs (3,3) and (5,2).
26 * The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.
27 * 
28 * 
29 * Example 2:
30 * 
31 * 
32 * Input: nums = [3,5,4,2,4,6]
33 * Output: 8
34 * Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).
35 * The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.
36 * 
37 * 
38 *  
39 * Constraints:
40 * 
41 * 
42 * 	n == nums.length
43 * 	2 <= n <= 10^5
44 * 	n is even.
45 * 	1 <= nums[i] <= 10^5
46 * 
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/
51// discuss: https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56    pub fn min_pair_sum(nums: Vec<i32>) -> i32 {
57        0
58    }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_1877() {
69    }
70}
71


Back
© 2025 bowen.ge All Rights Reserved.