Given a string `s` of lowercase letters, compute its reverse degree. Number the alphabet backwards, so 'a' is 26, 'b' is 25 and so on down to 'z' = 1. For every character, multiply that reversed value by the character's 1-indexed position in `s`, and add up all the products. Return the sum.
Given a string s of lowercase letters, compute its reverse degree. Number the alphabet backwards, so 'a' is 26, 'b' is 25 and so on down to 'z' = 1. For every character, multiply that reversed value by the character's 1-indexed position in s, and add up all the products. Return the sum.
Example 1:
Input: {"s":"abc"}
Output: 148
Constraints:
1≤s.length≤1000
s contains only lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"abc"}
Flip the alphabet so 'a' is worth 26 and 'z' is worth 1, then weigh each letter of "abc" by its position.