https://leetcode.com/problems/k-th-symbol-in-grammar/description/
class Solution { public: int kthGrammar(int N, int K, bool rootZero = true) { if (N == 1) return rootZero ? 0 : 1; int lastCnt = 1 << (N-2); if (K <= lastCnt) { return kthGrammar(N-1, K, rootZero); } else { return kthGrammar(N-1, K-lastCnt, !rootZero); } } };