We build a table of n rows (1-indexed). Row 1 is "0". To build each next row, look at the previous row and replace every 0 with "01" and every 1 with "10". Given n and k, return the k-th (1-indexed) symbol in row n.
We build a table of n rows (1-indexed). Row 1 is "0". To build each next row, look at the previous row and replace every 0 with "01" and every 1 with "10". Given n and k, return the k-th (1-indexed) symbol in row n.
Example 1:
Input: {"n":5,"k":12}
Output: 1
Constraints:
1≤n≤30
1≤k≤2n−1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":5,"k":12}
Row 1 is "0", and each row replaces 0 with "01" and 1 with "10". So every symbol is the parent of two children: the left child copies it, the right child flips it. We want position 12 of row 5.
■ path to targetleft child copiesright child flipsflips = 0