A support tool flags strange log lines, and one signal is a long run of characters that reads the same forward and backward.
Write longestMirror(line) that returns the longest substring of line that is a palindrome. If several have the same longest length, return the one that starts first. For an empty line, return an empty string.
Input: line = "xx_abcba-yy" Output: "abcba"
abcba has length 5; nothing longer reads the same both ways.
Input: line = "abcd" Output: "a"
Every single letter is a palindrome of length 1; a starts first.
0 <= line.length <= 3000line 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 #608 Longest Mirrored Run in a Log Line. 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.