Practice Count K-Subsequences of a String With Maximum Beauty
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Count K-Subsequences of a String With Maximum Beauty
Problem Statement
For each character c, let f(c) be its frequency in the entire string s. A valid subsequence chooses k positions in increasing order and contains k distinct characters. Its beauty is the sum of f(c) over those characters. Count valid subsequences with the greatest possible beauty, modulo 10^9 + 7. Different position choices count separately even when they spell the same text; return 0 if no valid subsequence exists.
Source: Count K-Subsequences of a String With Maximum Beauty on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "bcca", k = 2
4
# Example 2
s = "abbcd", k = 4
2
Constraints
Related LeetCode Problems
Practice more problems similar to Count K-Subsequences of a String With Maximum Beauty.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.