Pattern match🔗 Concept powering this problem
Ω
Big O & Complexity
0 of 10 sections complete
↗🎯 Pattern recognition check
Before coding: identify why big o & complexity works here.
Why algorithm efficiency matters. Time vs space tradeoffs and how to read Big-O notation.
Problem
Check whether a string is a valid palindrome, considering only letters and digits (and treating uppercase and lowercase as the same). Strip everything else out — punctuation, spaces, symbols — then check if what remains reads the same forwards and backwards.
Examples
Example 1
Input: s = "A man, a plan, a canal: Panama"
Output: true
// "amanaplanacanalpanama" is a palindrome.
Example 2
Input: s = "race a car"
Output: false
// "raceacar" is not a palindrome.
Example 3
Input: s = " "
Output: true
// After removing non-alphanumeric characters, s is an empty string — which reads the same forward and backward.
Constraints
- 1 ≤ s.length ≤ 2 × 10⁵
- s consists only of printable ASCII characters
⚡Focus on reducing time complexity from the naive solution.