Skip to content

Practice Partition Array Into Two Arrays to Minimize Sum Difference

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2035
LeetCode Problem

Partition Array Into Two Arrays to Minimize Sum Difference

Problem Statement

You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays. Return the minimum possible absolute difference.

Source: Partition Array Into Two Arrays to Minimize Sum Difference on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,9,7,3]
Output
2

# Example 2

Input
nums = [-36,36]
Output
72

# Example 3

Input
nums = [2,-1,0,4,-2,-9]
Output
0

Constraints

1 <= n <= 15
nums.length == 2 * n
-10^7 <= nums[i] <= 10^7

Related LeetCode Problems

Practice more problems similar to Partition Array Into Two Arrays to Minimize Sum Difference.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.