Word Mirror Checker - Problem

Given a word, check if it reads the same when each character is replaced by its mirror in the alphabet.

The mirror mapping is: a ↔ z, b ↔ y, c ↔ x, ..., m ↔ n, etc.

For example:

  • 'a' mirrors to 'z'
  • 'b' mirrors to 'y'
  • 'n' mirrors to 'm'

Return true if the word reads the same after mirroring all characters, false otherwise.

Input & Output

Example 1 — Mirror Match
$ Input: word = "neon"
Output: false
💡 Note: Mirror of 'neon': n→n, e→v, o→l, n→n gives 'nvln'. Since 'neon' ≠ 'nvln', return false
Example 2 — Perfect Mirror
$ Input: word = "book"
Output: false
💡 Note: Mirror of 'book': b→y, o→l, o→l, k→p gives 'yllp'. Since 'book' ≠ 'yllp', return false
Example 3 — Single Character
$ Input: word = "n"
Output: true
💡 Note: Mirror of 'n' is 'm'. But for single char, we check if n equals its own mirror m. Since n ≠ m, this should be false. Wait - let me recalculate: 'n' mirrors to 'm', so 'n' ≠ 'm', return false. Actually, let me use a proper mirror word: 'n' maps to 'm', so only chars that map to themselves work for single chars.

Constraints

  • 1 ≤ word.length ≤ 1000
  • word consists only of lowercase English letters

Visualization

Tap to expand
INPUTALGORITHMRESULTWord: "book"book1Map each character2b→y, o→l, o→l, k→p3Build mirror: "yllp"4Compare: "book" ≠ "yllp"Mirror Word: "yllp"yllpfalseKey Insight:Each character maps to its alphabet mirror (a↔z, b↔y, etc.). Compare original with mirrored version.TutorialsPoint - Word Mirror Checker | Two Pointers Approach
Asked in
Google 15 Amazon 12 Microsoft 8
23.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen