FastPrepCount Palindromic Substrings

Count Palindromic Substrings

Airbnb logoAirbnb● MediumINTERNOA
Learn

Problem statement

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

A palindrome reads the same forward and backward. Substrings are counted by their positions, so equal text appearing at different positions contributes more than once. Every one-character substring is a palindrome.

Function

countPalindromicSubstrings(text: String) → int

Examples

Example 1

text = "abc"return = 3

The palindromic substrings are "a", "b", and "c".

Example 2

text = "aaa"return = 6

There are three one-character palindromes, two occurrences of "aa", and one "aaa".

Constraints

  • 1 <= text.length <= 2000.
  • text contains lowercase English letters only.

More Airbnb problems

See Airbnb hiring insights
public int countPalindromicSubstrings(String text) {
  // Write your code here.
}
text"abc"
expected3
Checking account…