FunctionRacerProblemsRace

Mirror Writing

EasyTwo pointersPython, JavaScript, TypeScript, Java, C++

Held up to a mirror, the letter b looks like d and p looks like q (and the other way round), while the letters i, l, m, n, o, t, u, v, w and x look like themselves. Every other letter has no mirror partner. A word is mirror-stable when its mirror image reads exactly like the word itself: reading the word from the right end to the left end, with b and d swapped and p and q swapped, gives the original word.

Return True if word is mirror-stable, otherwise False. A letter without a mirror partner anywhere in the word makes it False. The empty string is mirror-stable.

Example 1

word "bod"
returns true

Read backwards, d o b becomes b o d after swapping b and d: the same word.

Example 2

word "pod"
returns false

Read backwards, d o p becomes b o q, which is not pod.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems