Skip to the code
cf.
+25 XP

#607 Count Mirrored Snippets

medium

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.

Example 1

Input: text = "aba"
Output: 4

a, b, a, and aba.

Example 2

Input: text = "aaa"
Output: 6

Three a, two aa, and one aaa.

Constraints

  • 0 <= text.length <= 2000
  • text contains lowercase letters.
Saved in this browser

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).