Distinct k-length substrings
Your task
Given a string s and an integer k, return the number of distinct substrings of s that have exactly length k. If k is greater than len(s) or k <= 0, return 0. For example, in "banana" the length-2 substrings are "ba", "an", "na", "an", "na", of which 3 are distinct. The string can be long, so the intended solution slides a fixed-size window (a rolling hash being one classic way to do it).
Examples
distinct_substrings_of_len_k(s: str, k: int) -> intExample 1
Input
distinct_substrings_of_len_k("banana", 2)Output
3