Watch 10 video solutions for Total Characters in String After Transformations I, a medium level problem involving Hash Table, Math, String. This walkthrough by Ashish Pratap Singh has 1,002,307 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
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:
'z', replace it with the string "ab".'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.
Example 1:
Input: s = "abcyy", t = 2
Output: 7
Explanation:
'a' becomes 'b''b' becomes 'c''c' becomes 'd''y' becomes 'z''y' becomes 'z'"bcdzz"'b' becomes 'c''c' becomes 'd''d' becomes 'e''z' becomes "ab"'z' becomes "ab""cdeabab""cdeabab", which has 7 characters.Example 2:
Input: s = "azbk", t = 1
Output: 5
Explanation:
'a' becomes 'b''z' becomes "ab"'b' becomes 'c''k' becomes 'l'"babcl""babcl", which has 5 characters.
Constraints:
1 <= s.length <= 105s consists only of lowercase English letters.1 <= t <= 105