Tap here to switch tabs
Problem
Submissions

Problem: Find Mirror Score of a String

Try to solve the Find Mirror Score of a String problem.

Statement

You are given a string s.

Initially, all indices in the string are unmarked, and the total score is 00.

The mirror of a lowercase English letter is the letter at the same distance from the opposite end of the alphabet. For instance, the mirror of 'a' is 'z', the mirror of 'b' is 'y', and the mirror of 'c' is 'x'.

Traverse the string from left to right using an index i from 00 to s.length −1- 1:

  1. Find the closest unmarked index j such that j << i and s[j] is the mirror character of s[i].

  2. If such an index j exists, mark both i and j, and add i −- j to the total score.

  3. If no such index exists, move to the next index without modifying the score.

Return the total score after processing all indices.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Mirror Score of a String

Try to solve the Find Mirror Score of a String problem.

Statement

You are given a string s.

Initially, all indices in the string are unmarked, and the total score is 00.

The mirror of a lowercase English letter is the letter at the same distance from the opposite end of the alphabet. For instance, the mirror of 'a' is 'z', the mirror of 'b' is 'y', and the mirror of 'c' is 'x'.

Traverse the string from left to right using an index i from 00 to s.length −1- 1:

  1. Find the closest unmarked index j such that j << i and s[j] is the mirror character of s[i].

  2. If such an index j exists, mark both i and j, and add i −- j to the total score.

  3. If no such index exists, move to the next index without modifying the score.

Return the total score after processing all indices.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists only of lowercase English letters.