All problems
0624EasyMathBit ManipulationRecursionSimulation

Letter at a Position in the Growing Tag

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3304Find the K-th Character in String Game I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A label generator keeps one word, which starts out as the single letter "a".

In one round the generator takes the word it currently holds, makes a copy in which every letter is replaced by the next letter of the alphabet, so 'a' becomes 'b', 'b' becomes 'c' and so on, and then sticks that copy on the end of the word. The word therefore doubles in length each round: after the first round it reads "ab", after the second "abbc".

Rounds keep running until the word holds at least k letters. Return the k-th letter of the word, counting the first letter as position 1. The bound on k keeps every letter within the alphabet, so no letter ever has to step past 'z'.

Examples

Example 1

Input
k = 4
Output
"c"

After two rounds the word reads `"abbc"`, which already holds four letters, and its fourth letter is `"c"`.

Example 2

Input
k = 8
Output
"d"

After three rounds the word reads `"abbcbccd"`, and its eighth letter is `"d"`.

Example 3

Input
k = 12
Output
"d"

Four rounds give `"abbcbccdbccdcdde"`. Its twelfth letter is `"d"`.

Constraints

  • 1 <= k <= 500

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def kth_character(k: int) -> str:
Java
public char kthCharacter(int k)
September 7
Apply