Skip to content
BytePatterns

Symbol In A Doubling Row

MediumRecursion#recursion#halving~25m

Problem

Row 1 is the single symbol 0. Each later row is made from the one above by replacing every 0 with 01 and every 1 with 10, so row n has 2 to the n minus 1 symbols. Given a row number n and a position k counted from 1, return the symbol at that position. Row 30 has over half a billion symbols, so building rows is not an option.

Examples

Input:  n = 4, k = 5
Output: 1
Why:    the rows are 0, 01, 0110, 01101001
Input:  n = 2, k = 2
Output: 1
Input:  n = 1, k = 1
Output: 0
Why:    edge case, the seed row itself

Hints

0 / 3

Stuck on the idea rather than the code? Recursion Basics covers it.