Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/volynetstyle/partition-array-into-two-arrays-to-minimize-sum-difference
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.
https://github.com/volynetstyle/partition-array-into-two-arrays-to-minimize-sum-difference
Last synced: 16 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/volynetstyle/partition-array-into-two-arrays-to-minimize-sum-difference
- Owner: volynetstyle
- Created: 2023-04-21T14:06:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-21T14:12:39.000Z (almost 2 years ago)
- Last Synced: 2024-11-12T00:36:30.694Z (3 months ago)
- Language: C++
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Partition-Array-Into-Two-Arrays-to-Minimize-Sum-Difference
Return the minimum possible absolute difference.
Example 1:
Input: nums = [3,9,7,3]
Output: 2
Explanation: One optimal partition is: [3,9] and [7,3].
The absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.Example 2:
Input: nums = [-36,36]
Output: 72
Explanation: One optimal partition is: [-36] and [36].
The absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.Example 3:
Input: nums = [2,-1,0,4,-2,-9]
Output: 0
Explanation: One optimal partition is: [2,4,-9] and [-1,0,-2].
The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0.Constraints:
1 <= n <= 15
nums.length == 2 * n
-107 <= nums[i] <= 107