Compute a score by matching characters with their mirrored counterparts in a string.
Problem
Given a string s, compute its mirror score by pairing each character with the matching mirrored character in the alphabet.
For a lowercase letter c, its mirror is the letter equidistant from the opposite end of the alphabet:
a ↔ zb ↔ yc ↔ x- ...
Scan the string and associate letters with their mirror counterparts according to the problem's scoring rule. The exact score is determined by the first valid mirror pairing behavior defined by the string order: whenever a character can be paired with a previous unmatched mirrored character, that pair contributes to the score.
Return the total mirror score for the string.
This is a string-processing problem that rewards careful character matching and tracking previously seen letters.
Input Format
- A single string
sconsisting of lowercase English letters.
Output Format
- Return an integer representing the mirror score of
s.
Constraints
1 <= s.length <= $10^{5}$scontains only lowercase English letters.
Example 1
Input
s = "azby"
Output
2
Explanation
a pairs with z, and b pairs with y, so the total mirror score is 2.
Example 2
Input
s = "abca"
Output
0
Explanation
No valid mirror pair is formed under the left-to-right matching rule.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.