Back to feed
Dev.to
Dev.to
7/15/2026
Manacher's Algorithm for Longest Palindromic Substring in O(N)

Manacher's Algorithm for Longest Palindromic Substring in O(N)

Original: ✅ Beats 99.44% | O(N) Manacher's Algorithm with Mirror Boundary Optimization

Short summary

A detailed walkthrough of Manacher's Algorithm for finding the longest palindromic substring in O(n) time. The post explains the intuition behind transforming the input string to handle odd/even palindromes uniformly, using mirror symmetry to skip redundant comparisons, and maintaining center/right boundary tracking. Includes a complete Python implementation with step-by-step complexity analysis.

  • Manacher's Algorithm finds longest palindromic substring in O(n) using mirror symmetry
  • String transformation with # and sentinels unifies odd/even palindrome handling
  • Complete Python implementation with linear time and space complexity

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more