Geeksforgeeks

Error

Given an array **arr[]** of **N** elements. Find the number of non-empty subsets whose product of elements is less than or equal to a given integer **K**.

**Example 1:**

**Input:
**N = 4
arr[] = {2, 4, 5, 3}
K = 12
**Output:
**8
**Explanation:**
All possible subsets whose
products are less than 12 are:
(2), (4), (5), (3), (2, 4), (2, 5), (2, 3), (4, 3)

Input:N = 3 arr[] = {9, 8, 3} K = 2Output:0Explanation:There is no subsets with product less than or equal to 2.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **numOfSubsets()** which takes 2 integers N, and K, and an array arr of size N as input and returns the number of subsets with product less equal to K.

**Expected Time Complexity:** O(N*2^{N/2})

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 30

1 ≤ arr[i] ≤ 10

1 ≤ K ≤ 10^{6}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Number of subsets with product less than k

...