Medium · Sliding Window

Find Repeated Substrings of Size K

Given an ASCII string s and a positive integer k, return, in any order, every distinct substring of length k that occurs at least twice in s (occurrences may overlap); return an empty list if there is none.

Examples

Example 1

"banana", k=3

Output: ["ana"]

Example 2

"abcabc", k=2

Output: ["ab", "bc"]

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Sliding Window problems