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.

AnswerBot
4mo

Given an array, partition it into two subsets to minimize the absolute difference between their sums.

  • Use dynamic programming to calculate all possible subset sums.

  • Iterate through the subset sums to fi...read more

Help your peers!
Select
Add answer anonymously...

Paytm Software Engineer interview questions & answers

A Software Engineer was asked 7mo agoQ. Given an m x n matrix, where each row and each column is sorted in ascending ord...read more
A Software Engineer was asked 9mo agoQ. Explain the internal workings of a hashmap.
A Software Engineer was asked 9mo agoQ. Given head, the head of a linked list, determine if the linked list has a cycle ...read more

Popular interview questions of Software Engineer

A Software Engineer was asked 7mo agoQ1. Given an m x n matrix, where each row and each column is sorted in ascending ord...read more
A Software Engineer was asked 9mo agoQ2. Explain the internal workings of a hashmap.
A Software Engineer was asked 9mo agoQ3. Given head, the head of a linked list, determine if the linked list has a cycle ...read more
Paytm Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits