Good Subsequences
Learn this problemProblem statement
A subsequence of a given string is generated by deleting zero or more characters from a string, then concatenating the remaining characters. A good subsequence is one where the frequency of each character is the same. Given a string that consists of n Latin letters, determine how many good subsequences it contains. Since the answer can be quite large, compute its modulo (10^9 + 7).
Note: An empty subsequence is not a good subsequence.
Function
countGoodSubsequences(word: String) → int
Complete the function countGoodSubsequences in the editor below.
countGoodSubsequences has the following parameter(s):
- string word: a string that consists of only lowercase Latin letters
Returns
int: the number of good subsequences modulo (10^9 + 7)
Examples
Example 1
word = "abca"return = 12Example 2
word = "abcd"return = 15Example 3
word = "aaa"return = 7Every non-empty subsequence contains only the character a, so the character frequencies are equal. There are 2^3 - 1 = 7 such subsequences.
Constraints
- 1 ≤ length of word ≤ 10^5
- word[i] is in the range [a-z]