LeetCode 647's Expand-Around-Centers: Tracing Palindromes That Unravel Strings
LeetCode 647 hits you with 'babad' and asks: how many palindromic substrings lurk inside? The expand-around-centers trick counts them all in O(n²), no extra space wasted.
⚡ Key Takeaways
- Expand-around-centers counts all palindromic substrings in O(n²) time with O(1) space by treating every position as a potential center. 𝕏
- Each expansion layer adds one palindrome, uniquely attributing them to centers to avoid overlaps. 𝕏
- Master this for interviews — it's the foundation for longest palindrome and beyond, intuitive over Manacher's complexity. 𝕏
Worth sharing?
Get the best Open Source stories of the week in your inbox — no noise, no spam.
Originally reported by Dev.to