Tap here to switch tabs
Problem
Submissions

Problem: Array Partition

Array Partition asks you to split an even-length integer array into pairs, then maximize the total of the smaller value selected from each pair. Values may be negative.

Statement

Given an integer array nums with an even number of elements, divide it into n pairs so that each element belongs to exactly one pair. For each pair, take the smaller value, and return the largest possible sum of these smaller values.

Note: n is half the length of nums.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • nums.length =2⋅n= 2 \cdot n

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Array Partition

Array Partition asks you to split an even-length integer array into pairs, then maximize the total of the smaller value selected from each pair. Values may be negative.

Statement

Given an integer array nums with an even number of elements, divide it into n pairs so that each element belongs to exactly one pair. For each pair, take the smaller value, and return the largest possible sum of these smaller values.

Note: n is half the length of nums.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • nums.length =2⋅n= 2 \cdot n

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4