π Description
Manacher's algorithm finds all palindromic substrings in linear time. Itβs especially useful for solving problems involving the longest palindromic substring or counting palindromes in a string.
π‘ Key Idea
- β Insert
#
between all characters and at boundaries to handle even/odd palindromes uniformly. - β Use the mirror property of palindromes to reduce redundant checks.
- β Expand around centers and maintain the rightmost boundary of known palindromes.
April 2, 2025About 2 min