Tap here to switch tabs
Problem
Submissions

Problem: Count K-Subsequences of a String With Maximum Beauty

med
30 min
Try to solve the Count K-Subsequences of a String With Maximum Beauty problem.

Statement

You are given a string s and an integer k.

A kk subsequence is a subsequence of s of length k that contains k distinct characters.

Let f(c)f(c) denote the frequency of character cc in s. The beauty of a kk subsequence is the sum of f(c)f(c) for all characters cc present in the subsequence.

Return the total number of kk subsequences that achieve the maximum possible beauty. Since the result may be large, return it modulo 109+710^9 + 7.

If no such subsequence exists, return 00.

Note:
Two subsequences are considered different if they are chosen from different sets of indices in s.

Constraints:

  • 1≤1 \leq s.length ≤2⋅105\leq 2 \cdot 10^5

  • 1≤1 \leq k ≤\leq s.length

  • s consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count K-Subsequences of a String With Maximum Beauty

med
30 min
Try to solve the Count K-Subsequences of a String With Maximum Beauty problem.

Statement

You are given a string s and an integer k.

A kk subsequence is a subsequence of s of length k that contains k distinct characters.

Let f(c)f(c) denote the frequency of character cc in s. The beauty of a kk subsequence is the sum of f(c)f(c) for all characters cc present in the subsequence.

Return the total number of kk subsequences that achieve the maximum possible beauty. Since the result may be large, return it modulo 109+710^9 + 7.

If no such subsequence exists, return 00.

Note:
Two subsequences are considered different if they are chosen from different sets of indices in s.

Constraints:

  • 1≤1 \leq s.length ≤2⋅105\leq 2 \cdot 10^5

  • 1≤1 \leq k ≤\leq s.length

  • s consists only of lowercase English letters.