366. Count the Number of Good Subsequences

A subsequence of a string is good if it is not empty and the frequency of each one of its characters is the same.

Given a string s, return the number of good subsequences of s. Since the answer may be too large, return it modulo 109 + 7.

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

Example 1:

Input: s = "aabb"

Output: 11

Explanation: The total number of subsequences is 24. There are five subsequences which are not good: "aab", "aab", "abb", "abb", and the empty subsequence. Hence, the number of good subsequences is 16-5 = 11.

Example 2:

Input: s = "leet"

Output: 12

Explanation: There are four subsequences which are not good: "leet", "lee", "eet", and the empty subsequence. Hence, the number of good subsequences is 16-4 = 12.

Now Your Turn!

Pick the correct output for the given input

Input: s = "hello"

Still unsure what the problem is asking ?

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

Constraints:

  • 1 <= s.length <= 104
  • s consists of only lowercase English letters.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int countGoodSubsequences(string s) {
// Your code goes here
}
};
Test Case

Input:

S