Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

52. Palindromic Substrings

MediumDay 16 of 60Strings

Given a string s, count how many of its substrings are palindromes. A substring is a contiguous block of characters, and substrings at different positions are counted separately even if they contain the same letters.

Example 1
Input: s = "abc"
Output: 3
Only the single letters "a", "b" and "c" are palindromes.
Example 2
Input: s = "aaa"
Output: 6
Three "a", two "aa" and one "aaa".
Constraints
  • 1 <= s.length <= 1000
  • `s` contains only lowercase English letters
Hints
Frequently asked at: Meta, Amazon, Microsoft, Paytm
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min