Trains the technique from
LeetCode 125Valid PalindromeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A word-game server accepts a submission phrase typed by a player and decides whether it counts as a mirror phrase.
The server judges it with two relaxations, applied before the comparison:
phrase, including spaces, punctuation and symbols, is skipped over entirely.After those relaxations, phrase is a mirror phrase when the kept characters spell the same thing read left to right as they do read right to left. Return true if it does and false if it does not.
A submission whose characters are all skipped keeps nothing at all, and nothing trivially matches itself, so those submissions are mirror phrases too.
Example 1
Dropping the spaces and the exclamation mark keeps steponnopets, which spells itself in reverse. Compared as typed it would fail, so the skipping rule is what decides this one.
Example 2
Nothing is skipped here. The capital D at the front lines up with the small d at the back, and folding case away makes them equal.
Example 3
The kept characters spell bellhop, whose reverse begins with p, so the very first comparison already disagrees.
Example 4
Not one letter or digit survives the first rule, leaving an empty run of characters, which the server accepts.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def is_mirror_phrase(phrase: str) -> bool:public boolean isMirrorPhrase(String phrase)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.