Reverse Degree of a Lowercase String

Quick Overview

Compute a lowercase string's reverse degree using reversed-alphabet letter values and original one-based positions. Include repeated letters and the full integer bounds.

Reverse Degree of a Lowercase String

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For a lowercase English string `s`, define its **reverse degree** by assigning each letter its position in the reversed alphabet: ```text a -> 26, b -> 25, ..., y -> 2, z -> 1 ``` Multiply each letter's assigned value by its one-based position in the original string, then add all the products. Return that sum. ### C++ Interface ```cpp class Solution { public: int reverseDegree(string s) { } }; ``` ### Examples **Example 1** ```text Input: s = "azb" Output: 103 ``` The products are `26 * 1 = 26`, `1 * 2 = 2`, and `25 * 3 = 75`. Their sum is `103`. **Example 2** ```text Input: s = "zz" Output: 3 ``` Each `z` has reversed-alphabet value `1`, so the sum is `1 * 1 + 1 * 2 = 3`. ### Constraints - `1 <= s.length <= 1000`. - `s` contains only lowercase English letters. ### Clarifying Questions - Is the string itself reversed? No. Its original positions remain unchanged; only the alphabet values are reversed. - Are positions zero-based? No. The first character has position `1`. - Do repeated letters contribute separately? Yes, once for each position where they appear. ### What a Strong Answer Covers - The exact reversed-alphabet values and one-based string positions. - A contribution from every character, including repeated letters. - Correct behavior for a single character and letters at both alphabet endpoints. - Resource and numeric bounds for strings of length `1000`. ### Follow-up Questions - Can two strings containing the same letters in different orders have different reverse degrees? - What would the definition become if every string position had the same weight instead of its one-based index? ```hint Translate the letter value For a lowercase letter, subtract its distance from `a` from 26. Combine that value with the character's one-based string position. ```

Overview: Compute a lowercase string's reverse degree using reversed-alphabet letter values and original one-based positions. Include repeated letters and the full integer bounds.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For a lowercase English string s, define its reverse degree by assigning each letter its position in the reversed alphabet:

a -> 26, b -> 25, ..., y -> 2, z -> 1

Multiply each letter's assigned value by its one-based position in the original string, then add all the products. Return that sum.

C++ Interface

class Solution {
public:
    int reverseDegree(string s) {
        
    }
};

Examples

Example 1

Input: s = "azb"
Output: 103

The products are 26 * 1 = 26, 1 * 2 = 2, and 25 * 3 = 75. Their sum is 103.

Example 2

Input: s = "zz"
Output: 3

Each z has reversed-alphabet value 1, so the sum is 1 * 1 + 1 * 2 = 3.

Constraints

  • 1 <= s.length <= 1000 .
  • s contains only lowercase English letters.

Clarifying Questions Guidance

  • Is the string itself reversed? No. Its original positions remain unchanged; only the alphabet values are reversed.
  • Are positions zero-based? No. The first character has position 1 .
  • Do repeated letters contribute separately? Yes, once for each position where they appear.

What a Strong Answer Covers Guidance

  • The exact reversed-alphabet values and one-based string positions.
  • A contribution from every character, including repeated letters.
  • Correct behavior for a single character and letters at both alphabet endpoints.
  • Resource and numeric bounds for strings of length 1000 .

Follow-up Questions Guidance

  • Can two strings containing the same letters in different orders have different reverse degrees?
  • What would the definition become if every string position had the same weight instead of its one-based index?