Count pattern occurrences

Write codeMedium20 min

Your task

Given a string s of lowercase letters and an integer k (1 <= k <= len(s) <= 10^5), let p be the prefix s[0:k]. Return the number of positions in s where p occurs as a contiguous substring, counting OVERLAPPING occurrences. If k is 0 or exceeds len(s), return 0.

Examples

count_good_substrings_period(s: str, k: int) -> int
Example 1
Inputcount_good_substrings_period("ababab", 2)
Output3