Skip to content

Practice Find Mirror Score of a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3412
LeetCode Problem

Find Mirror Score of a String

Problem Statement

A letter’s mirror is its counterpart in the reversed alphabet, such as a with z or b with y. Scan s from left to right with all positions initially unmarked and score zero. At position i, find the nearest earlier unmarked position j whose character is the mirror of s[i]. If one exists, mark both positions and add i - j to the score; otherwise leave i unmarked. Return the final score.

Source: Find Mirror Score of a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aczzx"
Output
5

# Example 2

Input
s = "abcdef"
Output
0

Constraints

1 <= s.length <= 10^5
s consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Find Mirror Score of a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.