word. Find the longest non-empty piece that the string both starts with and ends with. The whole string itself does not count, but the starting and ending copies may overlap.
Return that piece, or an empty string if there is none.word='abcab' → 'ab'
The word starts and ends with "ab". The longer starts "abc" and "abca" are not endings of the word.
word='aaab' → ''
The last letter "b" never appears at the start, so no such piece exists.
word='abababa' → 'ababa'
"ababa" is both the start and the end; the two copies overlap, which is allowed.
word consists of lowercase English lettersword='abcab'
'ab'
Run checks the first 3 tests in your browser. Submit checks all 165 tests on the server, hidden ones included.