FastPrepLongest Palindromic Substring
Problems/Longest Palindromic Substring

Longest Palindromic Substring

PeopleStrong logoPeopleStrong● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PeopleStrong onsite interview. The candidate reported a longest palindromic substring task and improving brute force into a better approach. We chose how ties break, what happens with empty input, and the limits. Our version is about 95% the same as the reported question.

Given a string s, return its longest consecutive substring that reads the same from left to right and right to left.

For this exercise, assume matching is case-sensitive. If several longest palindromic substrings exist, return the one that starts earliest in the input. An empty input returns an empty string. Explain a brute-force approach and improve it.

Function

longestPalindrome(s: String) → String

Examples

Example 1

s = "babad"return = "bab"

Both bab and aba have length 3. The earlier starting substring bab wins.

Example 2

s = "cbbd"return = "bb"

The two central b characters form the longest palindrome.

Constraints

  • For this exercise, assume 0 <= s.length <= 2000.
  • The string contains English letters and decimal digits.

More PeopleStrong Onsite Interview questions

  • Add Two Binary StringsONSITE INTERVIEW · Seen Mar 2026
  • Four SumONSITE INTERVIEW · Seen Mar 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Mar 2026
  • Sliding Window MaximumONSITE INTERVIEW · Seen Mar 2026
  • Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Sep 2025
  • Integer to English Words: Up to 20 DigitsONSITE INTERVIEW · Seen Sep 2025
  • Word Ladder II: All Shortest TransformationsONSITE INTERVIEW · Seen Sep 2025
  • Detect a Cycle in a Linked ListONSITE INTERVIEW · Seen May 2025
  • First Nonrepeating CharacterONSITE INTERVIEW · Seen May 2025
  • Longest Subarray with a Target SumONSITE INTERVIEW · Seen May 2025

Similar questions at other companies

  • Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Word Collection: Distance and AnagramsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Reverse File LinesCitadel · ONSITE INTERVIEWCitadel interview questions
  • Longest Palindromic Substring LengthMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • All Distinct Palindromic SubstringsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • String CompressionBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Strings at Most One Edit ApartExpedia · ONSITE INTERVIEWExpedia interview questions
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions

Interview reports that mention this question

  • PeopleStrong SDE OA and Interview Questions: 12 Experiences
All PeopleStrong interview questionsSee PeopleStrong hiring insights
Saved
class Solution {
    public String longestPalindrome(String s) {
        // Write your solution here.
    }
}
Checking account…