Count Substrings With K-Frequency Characters I

Given a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.

Example 1
Inputs = "abacb", k = 2
Output4
The valid substrings are "aba", "abac", "abacb", and "bacb".
Example 2
Inputs = "abcde", k = 1
Output15
All substrings are valid because every character appears at least once.

Constraints

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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate