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

Alice and Bob are playing a game. Initially, Alice has a string word = "a".
You are given a positive integer k. You are also given an integer array operations, where operations[i] represents the type of the ith operation.

Now Bob will ask Alice to perform all operations in sequence:

Example 1:
Input: k = 5, operations = [0,0,0]
Output: "a"
Explanation:
Initially, word == "a". Alice performs the three operations as follows:

Example 2:
Input: k = 10, operations = [0,1,0,1]
Output: "b"
Explanation:
Initially, word == "a". Alice performs the four operations as follows:

def kthCharacter(self, k: int, operations: List[int]) -> str:
	n, i = 1, 0
	while n < k:
		n *= 2
		i += 1
	d = 0
	while n > 1:
		if k > n // 2:
			k -= n // 2
			d += operations[i - 1]
		n //= 2
		i -= 1
	return chr(d % 26 + ord("a"))