K-th Symbol in Grammar Description link Solution See Code Code class Solution: def kthGrammar(self, N: int, K: int) -> int: return bin(K - 1).count('1') & 1