easyTwo PointersMicrosoftFacebookAmazon
Mirror Sign Verifier
A billboard installer tests whether a slogan reads the same from both ends after stripping punctuation and casing.
Given a string `text`, decide whether it is a palindrome after converting all letters to lowercase and removing non-alphanumeric characters.
Choose approach
a
0m
1a
2n
3a
4p
5l
6a
7n
8a
9c
10a
11n
12a
13l
14p
15a
16n
17a
18m
19a
201/23
Narrationstep 1 of 23
Cleaned "A man, a plan, a canal: Panama" to lowercase alphanumerics: "amanaplanacanalpanama". Set two pointers at the ends.
Variables
cleaned=amanaplanacanalpanama
lo=—
hi=—
How to think about it
- Strip the input to lowercase alphanumerics first — that's what the question actually asks about.
- Palindrome check = compare mirrored positions. Natural fit for two pointers.
- lo starts at 0, hi at length−1; step them toward each other.
- First mismatch → false. Pointers crossing → true.
- Alternative without cleaning: skip non-alphanumerics inline while walking.
Edge cases to catch in interview
- Empty string → vacuously true.
- All non-alphanumerics → cleans to empty → true.
- Single character → true.
- Case: 'Aa' → 'aa' → true.
Examples
Example 1
true{"text":"A man, a plan, a canal: Panama","values":["a","m","a","n","a","p","l","a","n","a","c","a","n","a","l","p","a","n","a","m","a"]}
'amanaplanacanalpanama' reads the same both ways.
Example 2
false{"text":"race a car","values":["r","a","c","e","a","c","a","r"]}
'raceacar' is not a palindrome.
Example 3
true{"text":" ","values":[]}
Cleans to the empty string.
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed