Count Palindromic Substrings
Updated
Problem statement
Given a non-empty string s, return the number of its palindromic substrings.
A palindrome reads the same from left to right and from right to left. Count substrings by occurrence, so equal text at different positions counts separately. Every one-character substring is a palindrome.
Function
countPalindromicSubstrings(s: String) → intExamples
Example 1
s = "abc"return = 3The three one-character substrings are palindromes.
Example 2
s = "aaa"return = 6The palindromic occurrences are three copies of a, two copies of aa, and one copy of aaa.
Example 3
s = "abba"return = 6The four individual characters, bb, and abba are palindromes.
Constraints
1 <= s.length <= 2000scontains only lowercase English letters.
More The Voleon Group Phone Screen questions
Similar questions at other companies
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- Edit DistanceDP World · PHONE SCREEN
- Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Decode WaysThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Edit DistanceAstrotalk · PHONE SCREEN
- Longest Palindromic SubstringeBay · PHONE SCREENeBay interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Generate One-Two Strings with Sum NGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions