 New update is available. Click here to update. Close
Topic list
Partition a set into two subsets such that the difference of subset sums is minimum.
HARD
10 mins 128 upvotes
Dynamic Programming
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter Dynamic Programming
-
- Arrays
-
-
Other topics
Problem solved
Skill meter Strings
-
- Matrices (2D Arrays)
-
- -
- Sorting
-
- Binary Search
-
- Stacks & Queues
-
- Trees
-
- Graph
-
- Greedy
-
- Tries
-
- SQL
-
- Binary Search Trees
-
- Heap
-
- Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Partition a set into two subsets such that the difference of subset sums is minimum.

Contributed by
Dhruv Sharma
Hard 0/120
Avg time to solve 10 mins
Success Rate 85 % Share 128 upvotes

## Problem Statement

#### Note:

``````1. Each element of the array should belong to exactly one of the subset.

2. Subsets need not be contiguous always. For example, for the array : {1,2,3}, some of the possible divisions are a) {1,2} and {3}  b) {1,3} and {2}.

3. Subset-sum is the sum of all the elements in that subset.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images ) ##### Sample Input 1:
``````1
4
1 2 3 4
``````
##### Sample Output 1:
``````0
``````
##### Explanation for sample input 1:
``````We can partition the given array into {2,3} and {1,4}, as this will give us the minimum possible absolute difference i.e (5-5=0) in this case.
``````
##### Sample Input 2:
``````1
3
8 6 5
``````
##### Sample Output 2:
``````3
``````
##### Explanation for sample input 2:
``````We can partition the given array into {8} and {6,5}, as this will give us the minimum possible absolute difference i.e (11-8=3) in this case
``````  Auto Console