FastPrepLongest Palindromic Substring
Problems/Longest Palindromic Substring

Longest Palindromic Substring

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a well-known problem, the longest palindromic substring, for the coding round. We fixed a tie rule that picks the earliest start, and we set how empty input works. Our version is about 97% the same as the named problem.

Given a string s, return the longest consecutive part that reads the same forward and backward.

When several longest palindromes exist, return the one that starts earliest in s. Return the empty string for empty input.

Function

longestPalindrome(s: String) → String

Examples

Example 1

s = "babad"return = "bab"

bab and aba both have length three; bab starts earlier.

Example 2

s = "cbbd"return = "bb"

The longest palindrome is the middle pair.

Example 3

s = ""return = ""

Empty input returns empty output.

Constraints

  • 0 <= s.length <= 2000.
  • s contains ASCII characters.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Longest Palindromic Substring LengthMicrosoft · ONSITE INTERVIEWMicrosoft 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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String longestPalindrome(String s) {
        // Write your code here.
    }
}
Checking account…