Mirror Sign Check
Easy · Two Pointers · about 12 min
A sign painter wants to know if a slogan reads the same forwards and backwards.
Only the English letters A-Z, a-z and the digits 0-9 count. Ignore everything else (spaces, punctuation, symbols), and treat upper and lower case as the same letter. Return True if what is left reads the same in both directions, otherwise False. Text with nothing left to read counts as True.
Examples:
is_mirror_sign("Step on no pets!") → True
is_mirror_sign("race a car") → False
is_mirror_sign("0P") → False (digits count too)
Try to do it with two indexes and no cleaned copy of the text.
Hints
- Use a left index at the start and a right index at the end.
- Before comparing, move each index past every character that is not a letter or digit (there may be several in a row).
- Compare the two characters in lower case; stop at the first mismatch.
Learn the pattern first: the Two Pointers lesson.
More Two Pointers problems
- Two Gifts for One Card (Easy)
- Squash Repeated Readings (Easy)
- Ledger Entries That Cancel Out (Medium)
- Biggest Tank Between Two Posts (Medium)
- Three Weights Closest to the Mark (Medium)
- Rain Caught on a Rooftop Row (Hard)