Tap here to switch tabs
Problem
Submissions

Problem: Array Partition

med
30 min
Try to solve the Array Partition problem.

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

med
30 min
Try to solve the Array Partition problem.

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