Reverse Degree of a String

Given a string s, calculate its reverse degree.

The reverse degree is calculated as follows:

  • For each character, multiply its position in the reversed alphabet ('a' = 26, 'b' = 25, ..., 'z' = 1) with its position in the string (1-indexed).
  • Sum these products for all characters in the string.

Return the reverse degree of s.

Example 1
Inputs = "abc"
Output148
The reverse degree is 26 + 50 + 72 = 148.
Example 2
Inputs = "zaza"
Output160
The reverse degree is 1 + 52 + 3 + 104 = 160.

Constraints

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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate