All problems
1153EasyString

The Roughness of a Strip of Letters

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3110Score of a String

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A strip strip holds lowercase letters. Its roughness is the total, taken over every pair of neighbouring letters, of how far apart the two sit in the alphabet.

Return the roughness.

Examples

Example 1

Input
strip = "abc"
Output
2

The two neighbouring pairs each sit one letter apart, so the roughness is 2.

Example 2

Input
strip = "az"
Output
25

The two letters sit at opposite ends of the alphabet, twenty-five places apart.

Example 3

Input
strip = "aaaa"
Output
0

Every letter is the same, so no pair is any distance apart at all.

Constraints

  • 2 <= strip.length <= 100
  • strip holds only lowercase English letters

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def score_of_string(strip: str) -> int:
Java
public int scoreOfString(String strip)
September 7
Apply