As reported: Siemens EDA, SDE-1 / 6-month internship + PPO, single ~2h20m technical interview (2026): the second DSA question. The brute force was coded and the expand-around-center approach was explained verbally.
Given a string s, return the longest substring of s that is a palindrome. If several have the maximum length, any one of them is accepted.
This is LeetCode 5 — Longest Palindromic Substring.
Example 1
s = "babad" -> "bab" ("aba" is also accepted)
Example 2
s = "cbbd" -> "bb"
Example 3
s = "a" -> "a"
Example 4
s = "ac" -> "a" ("c" is also accepted)
Constraints: 1 ≤ s.length ≤ 1000; s has only digits and English letters.
Code runner format: one line, s as a JSON string. Implement longestPalindrome(s); the harness checks that your answer is a palindromic substring of maximum length and prints "ok".