A chat app notices when a message ends the same way it began, like ok, I said ok, to suggest a shorter version.
Write echo(message) that returns the longest string that is both a prefix and a suffix of message, but is not the whole message. Return an empty string if there is none.
Input: message = "ok, I said ok" Output: "ok"
It starts with ok and ends with ok.
Input: message = "abab" Output: "ab"
ab is both the start and the end; abab itself doesn't count.
1 <= message.length <= 10^5message 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 #615 Prefix That Echoes at the End. 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.