Sum of Digits of String After Convert
You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:
- Convert
sinto an integer by replacing each letter with its position in the alphabet, i.e. replace'a'with1,'b'with2, ...,'z'with26. - Transform the integer by replacing it with the sum of its digits.
- Repeat the transform operation
ktimes in total.
Return the resulting integer after performing the operations described above.
Example 1
Input
s = "iiii", k = 1Output
36After converting
"iiii" to 9999, one transform gives 9 + 9 + 9 + 9 = 36.Example 2
Input
s = "leetcode", k = 2Output
6After converting
"leetcode" to 12552031545, the transforms produce 33 and then 6.Constraints
- 1 <= s.length <= 100
- 1 <= k <= 10
- s consists of lowercase English letters.