Skip to content
LC-3304 Easy LeetCode

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

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 73% Topics: Math, Bit Manipulation, Recursion, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(1)
# Space: O(1)

# bitmasks
class Solution(object):
    def kthCharacter(self, k):
        """
        :type k: int
        :rtype: str
        """
        def popcount(x):
            return bin(x)[2:].count('1')

        return chr(ord('a')+popcount(k-1)%26)

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions