Skip to content
Decoder

Palindromic Substrings

Medium

Problem

Return how many substrings of s are palindromes. Substrings at different positions count separately, even if they contain the same letters.

Example 1

Input
s = "abc"
Output
3
Why
"a", "b", "c"

Example 2

Input
s = "aaa"
Output
6
Why
"a" three times, "aa" twice, "aaa"

Constraints

  • 1 <= s.length <= 1000
  • s contains only lowercase letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.