Total Characters in String After Transformations I - Problem
You are given a string s and an integer t, representing the number of transformations to perform.
In one transformation, every character in s is replaced according to the following rules:
- If the character is
'z', replace it with the string"ab" - Otherwise, replace it with the next character in the alphabet
For example, 'a' is replaced with 'b', 'b' is replaced with 'c', and so on.
Return the length of the resulting string after exactly t transformations.
Since the answer may be very large, return it modulo 109 + 7.
Input & Output
Example 1 — Basic Transformation
$
Input:
s = "ab", t = 1
›
Output:
2
💡 Note:
After 1 transformation: 'a' becomes 'b', 'b' becomes 'c', so "ab" becomes "bc". Length is 2.
Example 2 — With 'z' Character
$
Input:
s = "z", t = 1
›
Output:
2
💡 Note:
After 1 transformation: 'z' becomes "ab", so "z" becomes "ab". Length changes from 1 to 2.
Example 3 — Multiple Transformations
$
Input:
s = "a", t = 2
›
Output:
1
💡 Note:
t=1: 'a'→'b', string becomes "b". t=2: 'b'→'c', string becomes "c". Final length is 1.
Constraints
- 1 ≤ s.length ≤ 105
- 1 ≤ t ≤ 109
- s consists only of lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code