Skip to main content
Back to problems
Leetcode
Medium
Strings
Hash Maps
Find Mirror Score Of A String

Compute a score by matching characters with their mirrored counterparts in a string.

Acceptance 0%
Problem Statement

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 ↔ z
  • b ↔ y
  • c ↔ 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 s consisting of lowercase English letters.

Output Format

  • Return an integer representing the mirror score of s.

Constraints

  • 1 <= s.length <= $10^{5}$
  • s contains only lowercase English letters.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.