Array Subset Partition Almost Equal Sum LeetCode (Partition a set into two subsets such that the difference of sum is minimum)

Given a set of integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum.

If there is a set S with n elements, then if we assume Subset1 has m elements, Subset2 must have n-m elements and the value of abs(sum(Subset1) – sum(Subset2)) should be minimum.

Example:
  1. Input:  arr[] = {1, 6, 11, 5}
  2. Output: 1
  3. Explanation:
    1. Subset1 = {1, 5, 6}, sum of Subset1 = 12
    2. Subset2 = {11}, sum of Subset2 = 11 

 This problem is very popular in GeeksForGeeks. A collection of hundreds of interview questions and solutions are available in our blog at Interview Question Solutions

Solution:

 

No comments:

Post a Comment