A copy-paste detector looks at a file as one long string and reports every fragment of exactly k characters that appears more than once. Occurrences may overlap.
Write repeatedFragments(text, k) that returns each such fragment once, ordered by the index where it first appears. Return an empty array if there are none.
Input: text = "abcXabcYabc", k = 3 Output: ["abc"]
abc appears three times; no other 3-character fragment repeats.
Input: text = "aaaa", k = 2 Output: ["aa"]
aa appears at 0, 1, and 2.
0 <= text.length <= 10^51 <= k <= 100text contains printable ASCII characters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #617 Repeated Fragments of Length k. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.