Longest Palindromic Substring Length
Updated
Problem statement
Given a string s, return the length of its longest palindromic substring.
A substring is a run of characters that are next to each other in s. A palindrome reads the same from left to right and from right to left. Every single character is a palindrome, so the answer is at least 1.
Function
longestPalindromeLength(s: String) → intExamples
Example 1
s = "forgeeksskeegfor"return = 10The substring geeksskeeg reads the same backwards and has length 10. No longer substring does.
Example 2
s = "abcd"return = 1No two neighbouring characters are equal and no character repeats, so the longest palindromic substring is a single character, length 1.
Example 3
s = "aba5aba"return = 7The whole string aba5aba is a palindrome with the odd centre 5, so the answer is 7.
Constraints
1 <= s.length <= 2000sconsists of lowercase English letters and digits.
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Longest Palindromic SubstringGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
- Longest Subsequence That Is a SubstringExpedia · OAExpedia interview questions
- Longest Palindromic SubstringInMobi · PHONE SCREENInMobi interview questions
- Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
- Longest Properly Closed Bracket RunAdobe · PHONE SCREENAdobe interview questions
- Indexed Proximity SearchStripe · PHONE SCREENStripe interview questions
- Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions