1.Palindrome checks
A palindrome reads the same forwards and backwards. Two pointers walking inward from both ends, comparing as they go, check this in O(n) without ever building a reversed copy.
Key features
- s == s[::-1] is the short, pythonic version — it builds a reversed copy, O(n) time and space
- The two-pointer version is also O(n) time, but O(1) extra space — no reversed copy is built
- A real-world palindrome check ("A man, a plan...") first needs to strip case, spaces, and punctuation
Two pointers closing in from both ends check a palindrome in O(n) time, O(1) space — and a real sentence needs its case and punctuation stripped first.