Suppose we have a string s and a number k, we have to find the number of k-length substrings of s, that occur more than once in s.
So, if the input is like s = "xxxyyy", k = 2, then the output will be 2
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s, k): from collections import Counter seen =  for i in range(len(s) - k + 1): t = s[i : i + k] seen.append(t) s = Counter(seen) return sum(1 for x in s.values() if x > 1) ob = Solution() print(ob.solve("xxxyyy",2))