The Find Mirror Score of a String interview question is a simulation and string matching problem. A character's "mirror" is its opposite in the alphabet (e.g., 'a' mirrors 'z', 'b' mirrors 'y'). As you iterate through a string, for each character , you look for its mirror character at a previous index that hasn't been "used" yet. If multiple exist, you pick the one closest to . The "score" is the sum of the distances for all such matched pairs.
Companies like Carwale use this to test your proficiency with Hash Tables and Stacks. It’s a variation of the "Valid Parentheses" problem but applied to alphabet mirrors. It evaluates whether you can efficiently manage "unmatched" characters and retrieve the most recent occurrence of a specific target.
This problem is solved using the Hash Table of Stacks pattern.
mirror(c) = 'z' - (c - 'a').i - j to the total score.String: "aczb"
stack['a'].stack['c'].stack['a'] has [0]. Pop 0. Score += .stack['b'].
Total Score: 2.Whenever you need to "match" an element with the "most recent" occurrence of something else, think of a Stack. Storing these stacks inside a Hash Map is a powerful way to handle multiple categories of "things to match" simultaneously. This is a common String interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Collisions on a Road | Medium | Solve | |
| Remove All Occurrences of a Substring | Medium | Solve | |
| Remove K-Balanced Substrings | Medium | Solve | |
| Removing Stars From a String | Medium | Solve | |
| Resulting String After Adjacent Removals | Medium | Solve |