FastPrepLongest Palindromic Substring Length
Problems/Longest Palindromic Substring Length

Longest Palindromic Substring Length

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. The review lists one longest-palindrome question, asking only for a length, with no input or rules. The round is not named. The process had an online assessment with two unnamed questions and an interview with a string question, which is the likely match.

The review does not say whether the palindrome must be a contiguous piece of the input, and gives no limits. Here it must be a contiguous run of the string (a substring), the input has lowercase letters and digits and up to 2000 characters, and you return its length.

Our version is about 85% the same as the reported question.

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) → int

Examples

Example 1

s = "forgeeksskeegfor"return = 10

The substring geeksskeeg reads the same backwards and has length 10. No longer substring does.

Example 2

s = "abcd"return = 1

No 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 = 7

The whole string aba5aba is a palindrome with the odd centre 5, so the answer is 7.

Constraints

  • 1 <= s.length <= 2000
  • s consists 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

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int longestPalindromeLength(String s) {
        // Write your code here.
    }
}
Checking account…