A survey crew encodes a hiking trail's elevation profile as a string of lowercase letters, one letter per checkpoint along the trail, where a letter's elevation reading is simply its 1-indexed position in the alphabet (a = 1, b = 2, ..., z = 26). To measure how rough the trail is, the crew defines its roughness score as the sum, over every pair of consecutive checkpoints, of the absolute difference between their elevation readings. Given the encoded profile, compute its roughness score.
A single line containing the string s, the trail's elevation profile.
Print a single integer: the roughness score of s.
1 <= length of s <= 1000s consists only of lowercase English lettersExample 1
Input
hello
Expected
13
Explanation
Elevations are h=8, e=5, l=12, l=12, o=15. Consecutive absolute differences are |8-5|=3, |5-12|=7, |12-12|=0, |12-15|=3. The total roughness score is 3+7+0+3=13.
Example 2
Input
zaz
Expected
50
Explanation
Elevations are z=26, a=1, z=26. Consecutive absolute differences are |26-1|=25 and |1-26|=25, for a total roughness score of 50.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →