Determine the character at position after repeatedly applying a simple string-growth rule.
Problem
You are given an initial string and a rule that grows the string in discrete rounds. In each round, the current string is transformed by appending a derived copy of itself according to the game rules.
Your task is to return the character that appears at 1-indexed position after the game has been played for enough rounds to make that position exist.
The exact transformation is simple enough that the answer can be reasoned about without building the entire final string.
Notes
- Positions are 1-indexed.
- The final string can become very large, so an efficient approach is expected.
- The problem is about identifying the character at a specific position after repeated deterministic growth.
Input Format
- An integer .
- The initial game rule is implied by the problem statement.
You may assume the requested position is valid for the generated string.
Output Format
- Return the single character at position in the generated string.
Constraints
- is valid for the generated string.
- The final string may be too large to construct explicitly.
- Use or near- extra space if possible.
Example 1
Input
k = 5
Output
b
Explanation
Using the game's deterministic growth rule, the character at position 5 can be traced back to the source segment and is 'b'.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.