Count Distinct Fixed-Length Substrings
Problem statement
Given a lowercase string text and an integer k, consider every contiguous substring of text whose length is exactly k.
Return the number of distinct substring values among those windows. Equal text appearing at different positions counts once.
Function
countDistinctSubstrings(text: String, k: int) → intExamples
Example 1
text = "ababa"k = 2return = 2The length-2 windows are ab, ba, ab, and ba. The distinct values are ab and ba.
Example 2
text = "aaaa"k = 2return = 1Every length-2 window is aa, so there is one distinct value.
Example 3
text = "abc"k = 1return = 3The one-character windows are a, b, and c, all distinct.
Constraints
1 <= text.length <= 10^5.textcontains only lowercase English letters.1 <= k <= text.length.
Source note: These two source-faithful panels preserve the complete March 12 Adobe OA task and its set-based solution notes.