
Asked in Goldman Sachs
Partition Set Into Two Subsets With Minimum Difference
Given an array of N non-negative integers, split the array into two subsets such that the absolute difference between their sums is minimized.
The task is to find the minimum absolute difference between the sums of any valid partition of the array elements.
Input:
The first line contains the integer T, representing the number of test cases.
For each test case:
- The first line contains an integer N, the number of elements in the array.
- The second line contains N space-separated integers, 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 new line.
Example:
Given the array [1, 2, 3], the partition can be [1, 2] and [3] or [1, 3] and [2]. The minimum absolute difference is 0 (possible by dividing as [2] and [1, 3]).
Constraints:
1 <= T <= 10
1 <= N <= 10^3
0 <= ARR[i] <= 10^3
0 <= SUM(ARR) <= 10^4
- Time Limit: 1 second
Note:
Each element of the array should be included in exactly one subset. Subsets need not be contiguous. Implement the function to compute the desired output, no need to handle input/output operations.

AnswerBot
4mo
Split array into two subsets with minimum absolute difference between their sums.
Use dynamic programming to find the minimum absolute difference between the sums of two subsets.
Iterate through all pos...read more
Help your peers!
Add answer anonymously...
Top Software Analyst Interview Questions Asked at Goldman Sachs
Q. Describe how to implement two stacks using a single array.
Q. What is the difference between SQL and NoSQL databases?
Q. Describe an SQL query you wrote that involved GROUP BY and JOIN clauses.
Interview Questions Asked to Software Analyst at Other Companies
Top Skill-Based Questions for Goldman Sachs Software Analyst
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

