3337. Total Characters in String After Transformations II Hard

@problem@discussion
#Hash Table#Math#String#Dynamic Programming#Counting



1/**
2 * [3337] Total Characters in String After Transformations II
3 *
4 * You are given a string s consisting of lowercase English letters, an integer t representing the number of transformations to perform, and an array nums of size 26. In one transformation, every character in s is replaced according to the following rules:
5 * 
6 * 	Replace s[i] with the next nums[s[i] - 'a'] consecutive characters in the alphabet. For example, if s[i] = 'a' and nums[0] = 3, the character 'a' transforms into the next 3 consecutive characters ahead of it, which results in "bcd".
7 * 	The transformation wraps around the alphabet if it exceeds 'z'. For example, if s[i] = 'y' and nums[24] = 3, the character 'y' transforms into the next 3 consecutive characters ahead of it, which results in "zab".
8 * 
9 * Return the length of the resulting string after exactly t transformations.
10 * Since the answer may be very large, return it modulo 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, nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2]</span>
15 * Output: <span class="example-io">7</span>
16 * Explanation:
17 * 
18 * 	
19 * 	First Transformation (t = 1):
20 * 	
21 * 		'a' becomes 'b' as nums[0] == 1
22 * 		'b' becomes 'c' as nums[1] == 1
23 * 		'c' becomes 'd' as nums[2] == 1
24 * 		'y' becomes 'z' as nums[24] == 1
25 * 		'y' becomes 'z' as nums[24] == 1
26 * 		String after the first transformation: "bcdzz"
27 * 	
28 * 	
29 * 	
30 * 	Second Transformation (t = 2):
31 * 	
32 * 		'b' becomes 'c' as nums[1] == 1
33 * 		'c' becomes 'd' as nums[2] == 1
34 * 		'd' becomes 'e' as nums[3] == 1
35 * 		'z' becomes 'ab' as nums[25] == 2
36 * 		'z' becomes 'ab' as nums[25] == 2
37 * 		String after the second transformation: "cdeabab"
38 * 	
39 * 	
40 * 	
41 * 	Final Length of the string: The string is "cdeabab", which has 7 characters.
42 * 	
43 * </div>
44 * <strong class="example">Example 2:
45 * <div class="example-block">
46 * Input: <span class="example-io">s = "azbk", t = 1, nums = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]</span>
47 * Output: <span class="example-io">8</span>
48 * Explanation:
49 * 
50 * 	
51 * 	First Transformation (t = 1):
52 * 	
53 * 		'a' becomes 'bc' as nums[0] == 2
54 * 		'z' becomes 'ab' as nums[25] == 2
55 * 		'b' becomes 'cd' as nums[1] == 2
56 * 		'k' becomes 'lm' as nums[10] == 2
57 * 		String after the first transformation: "bcabcdlm"
58 * 	
59 * 	
60 * 	
61 * 	Final Length of the string: The string is "bcabcdlm", which has 8 characters.
62 * 	
63 * </div>
64 *  
65 * Constraints:
66 * 
67 * 	1 <= s.length <= 10^5
68 * 	s consists only of lowercase English letters.
69 * 	1 <= t <= 10^9
70 * 	<font face="monospace">nums.length == 26</font>
71 * 	<font face="monospace">1 <= nums[i] <= 25</font>
72 * 
73 */
74pub struct Solution {}
75
76// problem: https://leetcode.com/problems/total-characters-in-string-after-transformations-ii/
77// discuss: https://leetcode.com/problems/total-characters-in-string-after-transformations-ii/discuss/?currentPage=1&orderBy=most_votes&query=
78
79// submission codes start here
80
81impl Solution {
82    pub fn length_after_transformations(s: String, t: i32, nums: Vec<i32>) -> i32 {
83        0
84    }
85}
86
87// submission codes end
88
89#[cfg(test)]
90mod tests {
91    use super::*;
92
93    #[test]
94    fn test_3337() {
95    }
96}
97


Back
© 2025 bowen.ge All Rights Reserved.