aboutsummaryrefslogtreecommitdiff
path: root/find_kth_char_str_game1.py
blob: 6b24764684a8dafbbac84cf032bbffec6cf434cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 3304. 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 forwever: 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'. return the value of the k'th character in 'word'
after enough operations have been done for 'word' to have at least 'k'
characters. note that character 'z' can be changed to 'a' in the operation.
"""


class Solution(object):
    def kthCharacter(self, k):
        """
        :type k: int
        :rtype: str
        """
        return chr(ord("a") + (k - 1).bit_count())


if __name__ == "__main__":
    obj = Solution()
    print(obj.kthCharacter(k=5))
    print(obj.kthCharacter(k=10))