The Blind 75 Leetcode Series: Palindromic Substring

Jonathan Chao
4 min readNov 16, 2023
Photo by Chris Ried on Unsplash

647. Palindromic Substrings

Given a string s, return the number of palindromic substrings in it.

A string is a palindrome when it reads the same backward as forward.

A substring is a contiguous sequence of characters within the string.

Given a string, we need to find all substrings that are palindromic, meaning the word is spelled the same reading from beginning or the end.

Note that we don’t have to print out the list of words (though it’s a small change in the code should we do) but only count the number of such substrings.

Before starting, let’s make sure of a few things:

  1. For questions involving strings, always check what type of string this is. In this case, are we only expecting lowercase letters? If we do expect uppercase, do we count uppercase and lowercase of the same letter the same?
  2. How long can the string be?
  3. If we see the same substirng, do we count the repeats?

If the interviewer tells us that we can expect only lowercase letters, and the string is…

--

--

Jonathan Chao
Jonathan Chao

Written by Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry

No responses yet