• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
May 25, 2024 |630 Views

PROBLEM OF THE DAY : 24/05/2024 | Partitions with Given Difference

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Siddhartha Hazra. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Dynamic Programming but also build up problem-solving skills.

In this problem, we are given an array arr, partition it into two subsets(possibly empty) such that each element must belong to only one subset. Let the sum of the elements of these two subsets be S1 and S2
Given a difference d, count the number of partitions in which S1 is greater than or equal to S2 and the difference between S1 and S2 is equal to d. Since the answer may be large return it modulo 109 + 7.

Example :

Input: n = 4
d = 3 
arr[] =  { 5, 2, 6, 4}

Output: 1

Explanation: There is only one possible partition of this array. Partition : {6, 4}, {5, 2}. The subset difference between subset sum is: (6 + 4) - (5 + 2) = 3.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/partitions-with-given-difference/1