Find the K-th Character in String Game I - Problem
Alice and Bob are playing an alphabet transformation game! Alice starts with a simple string word = "a", but Bob challenges her to keep expanding it using a special rule.
The Rule: In each operation, Alice must:
- Take each character in the current string
- Transform it to the next character in the alphabet (a→b, b→c, ..., z→a)
- Append this transformed string to the original
Example transformations:
"a"becomes"ab"(a + b)"ab"becomes"abbc"(ab + bc)"abbc"becomes"abbcbccd"(abbc + bccd)
Your task: Given a positive integer k, find the k-th character (1-indexed) in the final string after performing enough operations to have at least k characters.
Input & Output
example_1.py — Basic case
$
Input:
k = 5
›
Output:
b
💡 Note:
String evolution: 'a' → 'ab' → 'abbc' → 'abbcbccd'. The 5th character (1-indexed) is 'b'.
example_2.py — First character
$
Input:
k = 1
›
Output:
a
💡 Note:
The first character is always 'a' since we start with word = 'a'.
example_3.py — Power of 2
$
Input:
k = 4
›
Output:
c
💡 Note:
After 2 operations: 'abbcbccd'. The 4th character is 'c', which underwent 2 transformations (a→b→c).
Constraints
- 1 ≤ k ≤ 105
- The answer will always be a lowercase English letter
- k is 1-indexed (first character is at position 1)
Visualization
Tap to expand
Understanding the Visualization
1
Recognize the Pattern
String doubles each operation, following powers of 2
2
Binary Position Mapping
Each bit position corresponds to a generation of transformation
3
Count Transformations
Number of 1-bits = number of alphabet shifts applied
Key Takeaway
🎯 Key Insight: The binary representation of position k-1 directly tells us how many transformations to apply to 'a'!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code