JuniorString

Score of a String

You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.

Return the score of s.

Example 1
Inputs = "hello"
Output13
The ASCII differences are |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.
Example 2
Inputs = "zaz"
Output50
The ASCII differences are |122 - 97| + |97 - 122| = 25 + 25 = 50.

Constraints

  • 2 <= s.length <= 100
  • s consists only of lowercase English letters.

Asked at 5 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