3335. Total Characters in String After Transformations I Medium
1/**
2 * [3335] Total Characters in String After Transformations I
3 *
4 * 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:
5 *
6 * If the character is 'z', replace it with the string "ab".
7 * 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.
8 *
9 * Return the length of the resulting string after exactly t transformations.
10 * Since the answer may be very large, return it modulo<!-- notionvc: eb142f2b-b818-4064-8be5-e5a36b07557a --> 10^9 + 7.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">s = "abcyy", t = 2</span>
15 * Output: <span class="example-io">7</span>
16 * Explanation:
17 *
18 * First Transformation (t = 1):
19 *
20 * 'a' becomes 'b'
21 * 'b' becomes 'c'
22 * 'c' becomes 'd'
23 * 'y' becomes 'z'
24 * 'y' becomes 'z'
25 * String after the first transformation: "bcdzz"
26 *
27 *
28 * Second Transformation (t = 2):
29 *
30 * 'b' becomes 'c'
31 * 'c' becomes 'd'
32 * 'd' becomes 'e'
33 * 'z' becomes "ab"
34 * 'z' becomes "ab"
35 * String after the second transformation: "cdeabab"
36 *
37 *
38 * Final Length of the string: The string is "cdeabab", which has 7 characters.
39 * </div>
40 * <strong class="example">Example 2:
41 * <div class="example-block">
42 * Input: <span class="example-io">s = "azbk", t = 1</span>
43 * Output: <span class="example-io">5</span>
44 * Explanation:
45 *
46 * First Transformation (t = 1):
47 *
48 * 'a' becomes 'b'
49 * 'z' becomes "ab"
50 * 'b' becomes 'c'
51 * 'k' becomes 'l'
52 * String after the first transformation: "babcl"
53 *
54 *
55 * Final Length of the string: The string is "babcl", which has 5 characters.
56 * </div>
57 *
58 * Constraints:
59 *
60 * 1 <= s.length <= 10^5
61 * s consists only of lowercase English letters.
62 * 1 <= t <= 10^5
63 *
64 */
65pub struct Solution {}
66
67// problem: https://leetcode.com/problems/total-characters-in-string-after-transformations-i/
68// discuss: https://leetcode.com/problems/total-characters-in-string-after-transformations-i/discuss/?currentPage=1&orderBy=most_votes&query=
69
70// submission codes start here
71
72impl Solution {
73 pub fn length_after_transformations(s: String, t: i32) -> i32 {
74 0
75 }
76}
77
78// submission codes end
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 #[test]
85 fn test_3335() {
86 }
87}
88
Back
© 2025 bowen.ge All Rights Reserved.