Ctrl K

Total Jump Between Letters

Easy
You are given a string word. Walk through it from left to right and, for every pair of neighbouring letters, take the absolute difference of their ASCII codes. Return the sum of these values. For example, the codes in "bad" are 98, 97 and 100, so the answer is |98 − 97| + |97 − 100| = 1 + 3 = 4.
Example 1
word="code" → 24

Codes: c = 99, o = 111, d = 100, e = 101. The sum |99 − 111| + |111 − 100| + |100 − 101| = 12 + 11 + 1 = 24.

Example 2
word="aza" → 50

From a to z is 25, and back again another 25, so 50.

Example 3
word="mm" → 0
Constraints
  • 2 ≤ len(word) ≤ 100
  • word consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
word="code"
Expected
24

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.