Find the K-th Character in String Game I - Problem
Alice and Bob are playing a string transformation game. Initially, Alice has a string word = "a". You are given a positive integer k.
Bob will ask Alice to perform the following operation repeatedly:
- Generate a new string by changing each character in
wordto its next character in the English alphabet - Append this new string to the original
word
For example:
- Performing the operation on
"c"generates"cd"(c → d, then append) - Performing the operation on
"zb"generates"zbac"(z → a, b → c, then append)
Return the value of the k-th character in word, after enough operations have been performed for word to have at least k characters.
Input & Output
Example 1 — Basic Case
$
Input:
k = 5
›
Output:
b
💡 Note:
Step 0: "a" → Step 1: "ab" → Step 2: "abbc" → The 5th character (index 4) is 'b'
Example 2 — Small k
$
Input:
k = 1
›
Output:
a
💡 Note:
The 1st character is always 'a' since we start with "a"
Example 3 — Edge Case
$
Input:
k = 4
›
Output:
c
💡 Note:
Step 0: "a" → Step 1: "ab" → Step 2: "abbc" → The 4th character is 'c'
Constraints
- 1 ≤ k ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
k = 5 (find 5th character)
2
Process
String grows: a → ab → abbc → ...
3
Output
5th character is 'b'
Key Takeaway
🎯 Key Insight: The binary representation of (k-1) directly tells us how many character transformations to apply
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code