Valid Palindrome
Problem
Given a string s, decide whether it reads the same forwards and backwards once you ignore every character that is not a letter or digit and treat uppercase and lowercase letters as equal. An empty string, or one that contains no alphanumeric characters at all, counts as a palindrome.
sis at most 30,000 characters long; the empty string is a valid input.- Every character is printable ASCII (letters, digits, space, punctuation).
Examples
s = "Step on no pets!"→True. Dropping the space and the!and lowercasing leavessteponnopets, which is symmetric.s = "Top spot? Not."→False. The cleaned string istopspotnot; the outertpair matches, thenomatcheso, thenpis compared withnand the scan fails.s = "..."→True. Nothing survives the filter, so there is nothing to mismatch.
Hints
- What is the first pair of characters you would compare to prove or disprove symmetry, and what pair comes next?
- You do not need to build the cleaned string; you can skip over irrelevant characters as you go.
- Two pointers, one from each end, each advancing past non-alphanumeric characters before comparing case-folded values.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.