Tap here to switch tabs
Problem
Submissions

Problem: K-th Symbol in Grammar

K-th Symbol in Grammar starts with a single zero and builds each row by replacing each zero with zero-one and each one with one-zero. Given a row number and one-based position, return the symbol there.

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

K-th Symbol in Grammar starts with a single zero and builds each row by replacing each zero with zero-one and each one with one-zero. Given a row number and one-based position, return the symbol there.

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}