A playful username generator turns any name into a palindrome by adding letters at the end only.
Write mirrorName(name) that returns the shortest palindrome that starts with name, made by appending as few characters as possible to its end.
An empty name stays empty.
Input: name = "race" Output: "racecar"
e alone is the longest mirrored ending, so car (the reverse of rac) is appended.
Input: name = "abcb" Output: "abcba"
bcb is already mirrored, so only a is needed.
0 <= name.length <= 2000name 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 #609 Fewest Letters to Mirror a Name. 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.