Ctrl K

Alphabet Code Digit Rounds

Easy
You are given a word word of lowercase English letters and an integer rounds. First, replace every letter with its position in the alphabet (a → 1, b → 2, …, z → 26) and write those numbers one after another to form one long number. For example, "cab" becomes 312. Then, rounds times in a row, replace the number with the sum of its digits. Return the value left after the last round.
Example 1
word="bad", rounds=1 → 7

The letters become 2, 1, 4, giving 214. Its digit sum is 2 + 1 + 4 = 7.

Example 2
word="zoo", rounds=2 → 2

z = 26, o = 15, o = 15, giving 261515. Round one: 2 + 6 + 1 + 5 + 1 + 5 = 20. Round two: 2 + 0 = 2.

Example 3
word="k", rounds=3 → 2

k = 11, then 1 + 1 = 2, and 2 stays 2 from then on.

Constraints
  • 1 ≤ len(word) ≤ 100
  • 1 ≤ rounds ≤ 10
  • word consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyDrone Back on the Pad EasySame Text After Erasing Easy
loading Python…
Input
word="bad", rounds=1
Expected
7

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