#3337
Total Characters in String After Transformations II
expert · 1240 · lc hard +32 · 58.1% accepted · 385 likes · top 54%
Description
You are given a string s of lowercase English letters, an integer t representing the number of transformations to perform, and an array nums of size 26. In each transformation, every character in s is replaced as follows:
- Replace s[i] with the next nums[s[i] - 'a'] consecutive characters in the alphabet. For instance, if s[i] = 'a' and nums[0] = 3, then 'a' expands into "bcd".
- The replacement wraps around the alphabet when it exceeds 'z'. For example, if s[i] = 'y' and nums[24] = 3, then 'y' expands into "zab".
Return the length of the resulting string after exactly t transformations.
Since the answer may be very large, return it modulo 109 + 7.
Code
1
2
3