about | help | code help+videos | done | prefs |
You are given a string s. The score of the string is defined as the sum of the absolute differences between the ASCII values of every pair of adjacent characters. For example, if s = “hello”, the ASCII values of the characters are: h = 104, e = 101, l = 108, l = 108, o = 111. The score is calculated as |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13. If s = “zaz”, the ASCII values are z = 122 and a = 97. The score is |122 - 97| + |97 - 122| = 25 + 25 = 50. You can assume the input string will contain at least two characters. stringScore("hello") → 13 stringScore("zaz") → 50 stringScore("abc") → 2 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 305
Copyright Nick Parlante 2017 - privacy