Beginner-Friendly Python Solution | Reverse Alphabet Weighted Sum
IntuitionThe problem involves computing a "reverse degree" for a given string. The idea is to map each character to its "reverse position" in the alphabet (i.e.
# Intuition
The problem involves computing a "reverse degree" for a given string. The idea is to map each character to its "reverse position" in the alphabet (i.e., 'a' → 26, 'b' → 25, ..., 'z' → 1) and then multiply it by its position in the string.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1. Convert the string into a list of characters.
2. Iterate through each character in the string:
    * Compute its reverse position in the alphabet using:
        reverse=26−(ASCII value of character−ASCII value of ’a’)
    * Multiply this value by its (1-based) index in the string.
    * Accumulate the result in total.
3. Return the final computed total.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(n), since the loop iterates through the length of s once.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
O(1), as no extra data structures (except for a few variables) are used.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def reverseDegree(self, s: str) -> int:
        total = 0
        for i in range(len(s)):
            reverse = 26-(ord(s[i])-ord("a"))
            total+=reverse*(i+1)
        return total
```
['Python3']