Medium · Strings

Find repeated substrings size K

Given a string s and an 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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems