Longest Palindromic Substring
Updated
Problem statement
Given a string text, return its longest contiguous substring that is a palindrome.
If multiple palindromic substrings have the maximum length, return the one with the smallest starting index.
Function
longestPalindromicSubstring(text: String) → StringExamples
Example 1
text = "ababc"return = "aba"Both aba and bab have length 3. The substring aba starts earlier.
Example 2
text = "cbbd"return = "bb"The longest palindromic substring is bb.
Constraints
1 <= text.length <= 2000textcontains only lowercase English letters.
More InMobi Phone Screen questions
- House Robber IPHONE SCREEN · Seen Aug 2026
- Word Break IIPHONE SCREEN · Seen Aug 2026
- Bus Station Seat AllotmentPHONE SCREEN · Seen Mar 2026
- Find Missing and Duplicate IntegerPHONE SCREEN · Seen Mar 2026
- Frequency Equals Card ValuePHONE SCREEN · Seen Mar 2026
- Frog Position After T SecondsPHONE SCREEN · Seen Mar 2026
- IPOPHONE SCREEN · Seen Mar 2026
- Evaluate DivisionPHONE SCREEN · Seen Dec 2025
- Compare Version NumbersPHONE SCREEN · Seen Feb 2022
- Count Array DerangementsPHONE SCREEN · Seen Feb 2022
Similar questions at other companies
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Longest Properly Closed Bracket RunAdobe · PHONE SCREENAdobe interview questions
- Indexed Proximity SearchStripe · PHONE SCREENStripe interview questions
- Longest Palindromic Substring LengthMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Subsequence That Is a SubstringExpedia · OAExpedia interview questions
- Longest Palindromic SubstringGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions