Skip to content
LC-3307 Hard LeetCode

3307. Find the K-th Character in String Game II

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

# bitmasks
class Solution(object):
    def kthCharacter(self, k, operations):
        """
        :type k: int
        :type operations: List[int]
        :rtype: str
        """
        result = 0
        k -= 1
        for i in xrange(min(len(operations), k.bit_length())):
            if k&(1<<i):
                result = (result+operations[i])%26
        return chr(ord('a')+result)

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions