The copy-paste detector now wants the single longest fragment that appears at least twice in a file. Occurrences may overlap, so in aaaa the answer is aaa.
Write longestDuplicate(text) that returns that fragment. If several fragments share the longest length, return the one whose first appearance is earliest. If no character repeats at all, return an empty string.
Input: text = "banana" Output: "ana"
ana appears at index 1 and index 3 (overlapping).
Input: text = "abcd" Output: ""
No fragment appears twice.
0 <= text.length <= 3 * 10^4text contains lowercase letters.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 #618 Longest Duplicated Fragment. 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.