A word game awards a point for every mirrored snippet in the player's word: every substring that reads the same forward and backward. Snippets at different positions count separately, even if they are the same letters.
Write countMirrored(text) that returns the number of such substrings. Single letters count, and the empty string has none.
Input: text = "aba" Output: 4
a, b, a, and aba.
Input: text = "aaa" Output: 6
Three a, two aa, and one aaa.
0 <= text.length <= 2000text 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 #607 Count Mirrored Snippets. 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.