Partition Array Minimizing Subset Sum Difference

Given an array containing N non-negative integers, your task is to partition this array into two subsets such that the absolute difference between their sums is minimized. You only need to find the minimum absolute difference without outputting the subsets themselves.

Input:

The first line contains a single integer T, the number of test cases.
For each test case:
The first line contains an integer N, the size of the array.
The second line contains N space-separated integers denoting the array elements.

Output:

For each test case, output the minimum possible absolute difference on a new line.

Example:

Input:
T = 1
N = 3
Array = [1, 2, 3]

Output:
0

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^3
  • 0 <= ARR[i] <= 10^3
  • 0 <= SUM <= 10^4 (where SUM is the sum of array elements in a test case)

Note:

  • Each element must belong to exactly one subset.
  • Subsets do not need to be contiguous.
  • Subset-sum refers to the sum of elements within that subset.
AnswerBot
1y

The task is to partition an array into two subsets such that the absolute difference between subset sums is minimum.

  • Iterate through all possible subsets of the array

  • Calculate the sum of each subset

  • Fin...read more

Help your peers!
Select
Add answer anonymously...

NCR Corporation Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Longest Palindromic Substring Problem Statement You are provided with a string S...read more
A Software Developer Intern was asked Q. Count Distinct Ways to Reach the Nth Stairs Consider a scenario where you have b...read more
A Software Developer Intern was asked Q. Can you describe your projects and the tech stack you used in them?

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Longest Palindromic Substring Problem Statement You are provided with a string S...read more
A Software Developer Intern was asked Q2. Count Distinct Ways to Reach the Nth Stairs Consider a scenario where you have b...read more
A Software Developer Intern was asked Q3. Can you describe your projects and the tech stack you used in them?
NCR Corporation Software Developer Intern 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