3307. Find the K-th Character in String Game II Hard

@problem@discussion
#Math#Bit Manipulation#Recursion



1/**
2 * [3307] Find the K-th Character in String Game II
3 *
4 * Alice and Bob are playing a game. Initially, Alice has a string word = "a".
5 * You are given a positive integer k. You are also given an integer array operations, where operations[i] represents the type of the i^th operation.
6 * Now Bob will ask Alice to perform all operations in sequence:
7 * 
8 * 	If operations[i] == 0, append a copy of word to itself.
9 * 	If operations[i] == 1, generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original word. For example, performing the operation on "c" generates "cd" and performing the operation on "zb" generates "zbac".
10 * 
11 * Return the value of the k^th character in word after performing all the operations.
12 * Note that the character 'z' can be changed to 'a' in the second type of operation.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">k = 5, operations = [0,0,0]</span>
17 * Output: <span class="example-io">"a"</span>
18 * Explanation:
19 * Initially, word == "a". Alice performs the three operations as follows:
20 * 
21 * 	Appends "a" to "a", word becomes "aa".
22 * 	Appends "aa" to "aa", word becomes "aaaa".
23 * 	Appends "aaaa" to "aaaa", word becomes "aaaaaaaa".
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">k = 10, operations = [0,1,0,1]</span>
28 * Output: <span class="example-io">"b"</span>
29 * Explanation:
30 * Initially, word == "a". Alice performs the four operations as follows:
31 * 
32 * 	Appends "a" to "a", word becomes "aa".
33 * 	Appends "bb" to "aa", word becomes "aabb".
34 * 	Appends "aabb" to "aabb", word becomes "aabbaabb".
35 * 	Appends "bbccbbcc" to "aabbaabb", word becomes "aabbaabbbbccbbcc".
36 * </div>
37 *  
38 * Constraints:
39 * 
40 * 	1 <= k <= 10^14
41 * 	1 <= operations.length <= 100
42 * 	operations[i] is either 0 or 1.
43 * 	The input is generated such that word has at least k characters after all operations.
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii/
49// discuss: https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn kth_character(k: i64, operations: Vec<i32>) -> char {
55        '0'
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_3307() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.