Tap here to switch tabs
Problem
Submissions

Problem: Mirror Frequency Distance

Try to solve the Mirror Frequency Distance problem.

Statement

You are given a string s consisting of lowercase English letters and digits.

Each character has a corresponding mirror character:

  • For lowercase English letters, the iextthi^{ ext{th}} letter from the beginning of the alphabet is paired with the iextthi^{ ext{th}} letter from the end of the alphabet (such that 'a' pairs with 'z', 'b' pairs with 'y', and so on up to 'm' pairing with 'n').

  • For digits, each digit dd is paired with the digit 9−d9 - d (such that '0' pairs with '9', '1' pairs with '8', and so on up to '4' pairing with '5').

For every unique mirror pair (c,m)(c, m), let freq(c) and freq(m) denote the number of occurrences of characters cc and mm in s respectively.

Return the sum of ∣extfreq(c)−extfreq(m)∣| ext{freq}(c) - ext{freq}(m) | across all mirror pairs.

Constraints:

  • 1≤1 \leq s.length ≤5imes105\leq 5 imes 10^5

  • s consists only of lowercase English letters and digits.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Mirror Frequency Distance

Try to solve the Mirror Frequency Distance problem.

Statement

You are given a string s consisting of lowercase English letters and digits.

Each character has a corresponding mirror character:

  • For lowercase English letters, the iextthi^{ ext{th}} letter from the beginning of the alphabet is paired with the iextthi^{ ext{th}} letter from the end of the alphabet (such that 'a' pairs with 'z', 'b' pairs with 'y', and so on up to 'm' pairing with 'n').

  • For digits, each digit dd is paired with the digit 9−d9 - d (such that '0' pairs with '9', '1' pairs with '8', and so on up to '4' pairing with '5').

For every unique mirror pair (c,m)(c, m), let freq(c) and freq(m) denote the number of occurrences of characters cc and mm in s respectively.

Return the sum of ∣extfreq(c)−extfreq(m)∣| ext{freq}(c) - ext{freq}(m) | across all mirror pairs.

Constraints:

  • 1≤1 \leq s.length ≤5imes105\leq 5 imes 10^5

  • s consists only of lowercase English letters and digits.