A text editor plugin shows, for each character, how long the mirrored text centered on it is, as a little heat map.
Write mirrorLengths(text) that returns an array where entry i is the length of the longest odd-length palindrome centered on text[i]. Every entry is at least 1.
Text can be 200,000 characters long, and text like aaaa... makes growing from every letter one step at a time far too slow.
Input: text = "abacaba" Output: [1,3,1,7,1,3,1]
Around c the whole word mirrors (7); around each b, aba does (3).
Input: text = "aaaa" Output: [1,3,3,1]
The middle two letters each have aaa around them.
0 <= text.length <= 2 * 10^5text contains lowercase letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #612 Mirror Reach at Every Letter. 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.