← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Coding round at Meta for a software engineer role, focused entirely on palindrome substrings. The problem itself wasn't too bad but the follow-up about linear time had me scrambling a bit.

Questions Asked (1)

Q1

Given a lowercase ASCII string, count all palindromic substrings. Implement an O(n^2) expand-around-center solution, handle both odd and even length centers, then conceptually describe how you'd get it down to linear time. Walk through complexity and edge cases like empty strings, single characters, and all-identical-character strings.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I actually felt decent about the expand-around-center part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then implement the expand-around-center approach with separate handling for odd and even centers. After verifying with examples, discuss how Manacher's algorithm achieves linear time by reusing previously computed palindrome radii.

Pro tip: Emphasize that the O(n^2) solution is optimal for many practical cases, but knowing Manacher's algorithm demonstrates depth; however, be prepared to explain why it's rarely used in production due to constant factors and complexity.

1. Clarify and Define

Confirm the definition of a palindromic substring (contiguous) and discuss edge cases like empty string, single character, and all identical characters.

2. Expand Around Center

Explain that each palindrome has a center (odd: single char, even: between two chars). For each center, expand outward while characters match, counting each valid expansion.

3. Implement and Analyze

Write pseudocode or code for the O(n^2) solution. Analyze time complexity: O(n^2) due to n centers and O(n) expansion each; space O(1).

4. Optimize to Linear Time

Introduce Manacher's algorithm: transform string to handle even palindromes uniformly, maintain rightmost palindrome boundary and center, use symmetry to avoid redundant expansions.

5. Discuss Trade-offs

Compare O(n^2) and O(n) approaches: Manacher's is complex and has higher constant factors; O(n^2) is simpler and often sufficient. Mention edge case handling in both.

Key Points to Mention

  • Odd and even length palindromes require different center handling.
  • Time complexity O(n^2) and space O(1) for expand-around-center.
  • Edge cases: empty string returns 0, single character returns 1, all identical characters yield n(n+1)/2 palindromes.
  • Manacher's algorithm achieves O(n) by transforming the string and using a palindrome radius array.
  • Manacher's uses previously computed information to skip expansions, maintaining center and right boundary.
  • Trade-offs: Manacher's is optimal but complex; expand-around-center is simpler and often preferred in practice.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.