K-th Symbol in Grammar
Medium

Problem Statement

We build a table of N rows. The first row is 0. For every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given N and K, find the K-th (1-indexed) symbol in the N-th row.

Examples

1Example 1
Input:
{ "n": 1, "k": 1 }
Output:
0
2Example 2
Input:
{ "n": 2, "k": 1 }
Output:
0
3Example 3
Input:
{ "n": 2, "k": 2 }
Output:
1
Loading...

Sign in to Run Code and Submit