Count Number of Subsequences Problem Statement
Given an array of non-negative integers A
and an integer P
, determine the total number of subsequences of A
such that the product of any subsequence does not exceed P
.
Explanation
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Input
The first line contains a single integer T
denoting the number of test cases.
The first line of each test case contains two integers, N
(number of elements in the array) and P
.
The second line of each test case contains N
space-separated integers that make up A
.
Output
For each test case, print an integer denoting the count of subsequences with a product not exceeding P
. Print the result for each test case on a new line.
Example
Input:
A = [1, 2, 3], P = 4
Output:
5
Explanation:
All the subsequences are {1}, {2}, {3}, {1,2}, and {1,3} with products not exceeding 4. Thus, the count is 5.
Constraints
1 <= T <= 10
1 <= N <= 10^3
1 <= A[i] <= 10^3
1 <= P <= 10^3
- The sum of
N
over all test cases is <= 10^3.
Note
- Your solution should compute results modulo 109 + 7.
- No need to handle input/output as it's taken care of; implement the function directly.

AnswerBot
4mo
Count the number of subsequences of an array with product not exceeding a given value.
Iterate through all possible subsequences of the array
Calculate the product of each subsequence and check if it ex...read more
Help your peers!
Add answer anonymously...
Wipro Project Engineer interview questions & answers
A Project Engineer was asked 3d agoQ. Explain the logic behind determining if a number is prime.
A Project Engineer was asked 3w agoQ. Why have you not included C and C++ in your resume, considering you are a comput...read more
A Project Engineer was asked 1mo agoQ. Explain Interface with an example.
Popular interview questions of Project Engineer
A Project Engineer was asked 3d agoQ1. Explain the logic behind determining if a number is prime.
A Project Engineer was asked 3w agoQ2. Why have you not included C and C++ in your resume, considering you are a comput...read more
A Project Engineer was asked 1mo agoQ3. Explain Interface with an example.
Top HR questions asked in Wipro Project Engineer
A Project Engineer was asked 2mo agoQ1. What challenges did you face while working on the minor project?
A Project Engineer was asked 2mo agoQ2. Tell me about your final year project.
A Project Engineer was asked 2mo agoQ3. Would you prefer to work as a team leader or a team member?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

