medium1-D Dynamic ProgrammingFacebookAmazon
Palindrome Counter
A linguistics tool counts every mirror-reading slice (overlapping allowed) in a text sample.
Given a string, return the number of palindromic substrings in it (including duplicates at different positions).
Choose approach
a
0a
1a
2i
1/3
Narrationstep 1 of 3
Center 0: 1 odd + 1 even palindromes. Total = 2.
Variables
i=0
count=2
odd=1
even=1
How to think about it
- 2n − 1 centers.
- Each successful mirror match counts +1.
Edge cases to catch in interview
- Empty -> 0.
- All same chars -> n(n+1)/2.
Examples
Example 1
3{"s":"abc"}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed