Count Palindromic Substrings
Updated
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) → intExamples
Example 1
text = "abc"return = 3The palindromic substrings are "a", "b", and "c".
Example 2
text = "aaa"return = 6There are three one-character palindromes, two occurrences of "aa", and one "aaa".
Constraints
1 <= text.length <= 2000.textcontains lowercase English letters only.
More Airbnb Online Assessment questions
- Bouncing DiagonalsOA · Seen Dec 2026
- Count Numbers Not Equal to the First TwoOA · Seen Dec 2026
- Garden Sprinkler PlacementOA · Seen Dec 2026
- Theme Park Shuttle Wait TimeOA · Seen Dec 2026
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
Similar questions at other companies
- Longest Palindromic SubsequenceAXQ Capital · OA
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA