Problem intuition
- The naive route is to clean the string and compare it with its reverse.
- The more memory-efficient version keeps two pointers at the ends and skips every character that does not matter.
Ignore punctuation and case, then decide whether the string reads the same forward and backward.
Two PointersThe solutions below are ordered from least optimal to most optimal, so you can see the improvement path instead of only the final answer.
Solution 1
Solution 2