Find the K-th Character in String Game I

Alice and Bob are playing a game. Initially, Alice has a string word = "a".

You are given a positive integer k.

Now Bob will ask Alice to perform the following operation forever:

  • Generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original word.

For example, performing the operation on "c" generates "cd" and performing the operation on "zb" generates "zbac".

Return the value of the k^th character in word, after enough operations have been done for word to have at least k characters.

Example 1
Inputk = 5
Output"b"
After three operations, word becomes "abbcbccd", so the 5th character is "b".
Example 2
Inputk = 10
Output"c"
After enough operations for word to contain at least 10 characters, the 10th character is "c".

Constraints

  • 1 <= k <= 500

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate