Tap here to switch tabs
Problem
Submissions

Problem: K-th Symbol in Grammar

med
30 min
Try to solve the K-th Symbol in Grammar problem.

Statement

You start with row 11 containing a single symbol 00. To build row ii from row i−1i - 1, replace every 00 with 0101 and replace every 11 with 1010. Given n and k, return the value of the k th symbol in row n, where k is indexed from 11.

Note: Row n has length 2n−12^{n - 1}.

Constraints:

  • 1≤1 \leq n ≤30\leq 30

  • 1≤1 \leq k ≤2n−1\leq 2^{n - 1}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: K-th Symbol in Grammar

med
30 min
Try to solve the K-th Symbol in Grammar problem.

Statement

You start with row 11 containing a single symbol 00. To build row ii from row i−1i - 1, replace every 00 with 0101 and replace every 11 with 1010. Given n and k, return the value of the k th symbol in row n, where k is indexed from 11.

Note: Row n has length 2n−12^{n - 1}.

Constraints:

  • 1≤1 \leq n ≤30\leq 30

  • 1≤1 \leq k ≤2n−1\leq 2^{n - 1}