Minimum Subset Sum Difference Problem
Given an array of non-negative integers, your task is to partition this array into two subsets such that the absolute difference between the sums of the subsets is minimized.
Your goal is to find the minimum absolute difference possible for any valid partitioning of the array elements.
Input:
The first line contains the integer T, representing the number of test cases.
The first line of each test case contains the integer N, the size of the array.
The second line of each test case contains N space-separated integers which represent the elements of the array.
Output:
For each test case, return the minimum possible absolute difference between the sums of the two subsets on a separate line.
Example:
Input:
2
4
1 6 11 5
3
1 2 3
Output:
1
0
Constraints:
- 1 <= T <= 10
- 1 <= N <= 103
- 0 <= ARR[i] <= 103
- 0 <= SUM <= 104, where SUM is the total sum of the array for a given test case.
- Time Limit: 1 second
Note:
Each element in the array must belong to exactly one subset.
Subsets do not need to be contiguous. For instance, given the array {1,2,3}, some possible partitions are a) {1,2} and {3}, b) {1,3} and {2}.
Subset-sum refers to the sum of elements in that subset.
Be the first one to answer
Add answer anonymously...
Top Paytm Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Paytm Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app