Asked inBYJU'S,Intern

Count Subsequences Problem Statement

Given an integer array ARR of size N, your task is to find the total number of subsequences in which all elements are equal.

Explanation:

A subsequence of an array is derived by removing some of the elements of the array without changing the order of the remaining elements.

Input:

The first line contains an integer 'T' denoting the number of test cases. Each test case is as follows: The first line contains an integer 'N' denoting the size of the array. The second line contains 'N' space-separated integers representing the elements of the array.

Output:

For each test case, output the total number of subsequences where all elements are the same. Each test case's result should be printed on a new line.

Example:

Input:
2
3
1 1 2
4
3 3 3 3
Output:
3
14

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 105
  • 0 ≤ ARR[i] ≤ 109
  • Time Limit: 1 second

Note:

The result must be calculated modulo 109 + 7. Implement the function; you don't need to print anything.
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

Help your peers!
Select
Add answer anonymously...
BYJU'S Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits