Find the -th bit in a recursively defined binary string of length .
Find K-th Bit in N-th Binary String
gfgYou are given two integers and .
Define a binary string recursively as follows:
0, then appending the reverse of with every bit flipped (0 becomes 1, and 1 becomes 0).Your task is to return the -th character of using 1-based indexing.
This problem is designed to test your ability to reason about recursive structure without explicitly building the full string.
0 or 1.Example 1
Input
n = 3, k = 1
Output
0
Explanation
, so the first bit is 0.
Example 2
Input
n = 3, k = 5
Output
0
Explanation
, and the 5th bit is the middle bit 0.
Example 3
Input
n = 4, k = 11
Output
1
Explanation
The recursive string has length $15$. Tracing the position through mirrored halves gives bit 1 at index 11.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.