731. Count subsets with sum K

Given an array arr of n integers and an integer K, count the number of subsets of the given array that have a sum equal to K. Return the result modulo (109 + 7).

Example 1:

Input: arr = [2, 3, 5, 16, 8, 10], K = 10

Output: 3

Explanation: The subsets are [2, 8], [10], and [2, 3, 5].

Example 2:

Input: arr = [1, 2, 3, 4, 5], K = 5

Output: 3

Explanation: The subsets are [5], [2, 3], and [1, 4].

Now Your Turn!

Pick the correct output for the given input

Input: arr = [2, 2, 2, 2], K = 4

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  •  1 <= n <= 100
  • 1 <= arr[i] <= 103
  • 1 <= K <= 103

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution{
public:
int perfectSum(vector<int>&arr, int K){
}
};
Test Case

Input:

K
Arr