3412. Find Mirror Score of a String
You are given a string
s.We define the mirror of a letter in the English alphabet as its corresponding letter when the alphabet is reversed. For example, the mirror of
'a'is'z', and the mirror of'y'is'b'.Initially, all characters in the string
sare unmarked.You start with a score of 0, and you perform the following process on the string
s:
- Iterate through the string from left to right.
- At each index
i, find the closest unmarked indexjsuch thatj < iands[j]is the mirror ofs[i]. Then, mark both indicesiandj, and add the valuei - jto the total score.- If no such index
jexists for the indexi, move on to the next index without making any changes.Return the total score at the end of the process.
1 | class Solution { |