Longest Mirror-Symmetric Run Inside a Username
Last updated: November 29, 2026
Quick Overview
Given a username string, return the longest contiguous substring that reads the same forwards and backwards.
Meta
November 29, 20260
0
0 solved
Given a username string, return the longest contiguous substring that reads the same forwards and backwards.
Asked in Meta technical screens to see if you go beyond brute force quickly. Interviewers usually accept the O(n^2) center expansion with clean code, and may ask about the 2D DP view and Manacher's algorithm as follow-ups.
What the Interviewer Expects
- Explain the 2D DP: s[i:j] is a palindrome iff ends match and inside is a palindrome
- Prefer center expansion for O(1) space
- Handle both odd and even length centers
- Return the substring, not just the length
- Mention Manacher's for O(n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How does Manacher's algorithm reach linear time?
- How would you count all palindromic substrings?
- What if you may change one character to extend the palindrome?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a string of length 0 to 1000. Return one longest palindromic substring; ties may be broken by first occurrence. The empty string returns the empty string....
High-Level Design
The 2D DP formulation says pal[i][j] is true when s[i] == s[j] and pal[i+1][j-1] is true, which reveals that every palindrome grows outward from a center. That suggests skipping the table: for e...