#3412
Find Mirror Score of a String
expert · 1070 · lc medium +32 · 35.4% accepted · 124 likes · top 13%
Description
You are given a string s.
In the English alphabet, the mirror of a letter is its counterpart when the alphabet is reversed (e.g., the mirror of 'a' is 'z', the mirror of 'y' is 'b').
All characters start unmarked. Your score begins at 0. Process s from left to right:
- At index i, find the nearest unmarked index j < i where s[j] is the mirror of s[i]. Mark both i and j, and add i - j to the score.
- If no such j exists, skip index i.
Return the total score.
Code
1
2
3