Count Subsequences
You have been given an integer array/list 'ARR' of size 'N'. Your task is to return the total number of those subsequences of the array in which all the elements are equal.
A subsequence of a given array is an array generated by deleting some elements of the given array with the order of elements in the subsequence remaining the same as the order of elements in the array.
Note :
As this value might be large, print it modulo 10^9 + 7
Input format :
The first line contains an integer 'T' which denotes the number of test cases. Then the test cases follow :
The first line of each test case contains an integer 'N' representing the size of the array/list.
The second line contains 'N' single space - separated integers representing the elements of the array.
Output Format :
For each test case, print the total number of subsequences in which all elements are equal.
The output of each test case will be printed in a separate line.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 100
1 <= N <= 10^5
0 <= ARR[i] <= 10^9
Time Limit : 1 sec
AnswerBot
1y
The task is to count the number of subsequences in an array where all elements are equal.
Iterate through the array and count the frequency of each element.
For each element, calculate the number of sub...read more
CodingNinjas
author
2y
Brute Force
The idea is to generate all the subsequences and check whether the elements present are equal or not.
Here is the algorithm :
- Generate all the subsequences of the given array.
- Maintain a var...read more
CodingNinjas
author
2y
Combinations
In this approach, we will calculate the contribution of each distinct element to the answer. For example, if we had ‘k’ occurrences of an element in the array, we will be able to form :
- kC1...read more
Add answer anonymously...
Popular interview questions of Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app