Equal subset sum partition

5

2 votes
Problem

Problem Statement

You are given an array 'ARR' of 'N' positive integers. Your task is to find if we can partition the given array into two subsets such that the sum of elements in both subsets is equal.

For example, let’s say the given array is [2, 3, 3, 3, 4, 5], then the array can be partitioned as [2, 3, 5], and [3, 3, 4] with equal sum 10.

Follow Up:

Can you solve this using not more than O(S) extra space, where S is the sum of all elements of the given array?

Input Format:

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

Output Format:

For each test case, return “true” or “false” denoting whether we can partition into two equal subset-sum or not.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

for first case, the array can be partitioned as ([2,2,1], and [1,1,3]) or ([2,1,1,1] and [3, 2]) with subest sum 5. For the second test case, the array can’t be partitioned.

Editor Image

?