Skip to content
Onsite

K-Length Substrings With No Repeated Characters

MediumP3Coding

Given a string s of lowercase letters and an integer k, count the substrings of length exactly k whose characters are all different (that is, exactly k distinct characters). Substrings are counted by position.

Example 1

Input
s = "abcabc", k = 3
Output
4

Example 2

Input
s = "aaaa", k = 2
Output
0

Example 3

Input
s = "abcd", k = 1
Output
4

Constraints

  • 1 <= s.length <= 10^5
  • 1 <= k <= 10^5
  • s consists of lowercase English letters.

Hints

Run checks the 3 visible tests, Submit all 12.