Longest Palindromic Substring
Updated
Problem statement
Given a string s, return its longest palindromic substring. A palindrome reads the same forwards and backwards.
- Only substrings of length
2or more count; a single character is not accepted as an answer. - If several palindromes have the same longest length, return the one that starts first in
s. - If no substring of length
2or more is a palindrome, return"None".
Function
longestPalindromicSubstring(s: String) → StringExamples
Example 1
s = "babad"return = "bab""bab" and "aba" are both palindromes of length 3, and nothing longer is. "bab" starts first (at index 0), so it is the answer.
Example 2
s = "cbbd"return = "bb"The only palindrome of length 2 or more is "bb".
Constraints
1 ≤ s.length ≤ 1000scontains only digits and English letters.
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 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