Ctrl K

Counting Palindromic Pieces of a String

Medium
You get a string text. Count how many of its contiguous substrings are palindromes, meaning they read the same forwards and backwards. Substrings with the same content but at different positions are counted separately. Every single letter is a palindrome too.
Example 1
text="level" → 7

Five single letters, plus "eve" and "level", for 7 in total.

Example 2
text="zzz" → 6

Three "z" pieces, two "zz" pieces (different positions count separately) and "zzz", for 6.

Example 3
text="map" → 3
Constraints
  • 1 ≤ len(text) ≤ 1000
  • text consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Mirror Fragment MediumFalling Domino Row MediumWord Growth Chain MediumNearly Matching Picks MediumErasable Marked Letters Medium
loading Python…
Input
text="level"
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 142 tests on the server, hidden ones included.