Map Characters and Sum
EasyP3Coding
Map the letters of the alphabet to consecutive numbers starting at num: a maps to num, b to num + 1, c to num + 2, and so on. Return the sum of the mapped values of the first k characters of the lowercase string s.
For num = 30, s = "abc" and k = 3 the result is 30 + 31 + 32 = 93.
Example 1
- Input
- num = 30, s = "abc", k = 3
- Output
- 93
Example 2
- Input
- num = 1, s = "abc", k = 2
- Output
- 3
Example 3
- Input
- num = 0, s = "a", k = 1
- Output
- 0
Constraints
- 1 <= k <= s.length <= 10^5
- 0 <= num <= 1000
- s consists of lowercase letters.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.