text of lowercase English letters. A repeat is a contiguous piece of the string that occurs in it at least twice. The occurrences may overlap.
Return the longest repeat. If several repeats share the maximum length, return the one whose second occurrence starts earliest, that is, the one you would see repeat first while reading the string left to right. If no piece repeats, return an empty string.text='abracadabra' → 'abra'
The piece "abra" occurs at the start and at the end, and no piece of length 5 occurs twice.
text='aaaa' → 'aaa'
"aaa" starts at position 0 and at position 1: occurrences may overlap.
text='xyz' → ''
All letters differ, nothing repeats, so the answer is the empty string.
text consists of lowercase English letterstext='abracadabra'
'abra'
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.