The problem. Build a table of rows: row 1 is 0. To make each next row, replace every 0 in the row before with 01 and every 1 with 10. Given n and k, return the k-th symbol (1-indexed) of row n.
n = 1, k = 1 -> 0
n = 2, k = 1 -> 0
n = 2, k = 2 -> 1
n = 4, k = 6 -> 0 (row 4 is 01101001)Members only · free account
The rest of this lesson, with 8 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson