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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
Palindromic substring
Center expansion
2D dynamic programming
String scanning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported