15% off all plans & roadmaps Use code
See plansLeetCode 125 · Solution & editorial
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Valid Palindrome is a String Manipulation Patterns problem, in the Palindrome Check (Two Pointers / Reverse) subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Master palindrome checking using two pointers. Handle valid palindrome with alphanumeric and one removal cases.
The reference solution runs in O(n) time and O(1) space.
Valid Palindrome has been reported in interviews at Facebook, Microsoft, Apple, Wayfair, Amazon, Yandex, Bloomberg, Oracle.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Valid Palindrome is a String Manipulation Patterns problem, in the Palindrome Check (Two Pointers / Reverse) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.