findKthBit
that takes n
and k
as arguments.n
is 1, return '0' as S1
is always '0'.Sn
which is 2^n - 1
.Sn
which is length / 2 + 1
.k
is equal to the middle index, return '1'.k
is less than the middle index, recursively call findKthBit
with n-1
and k
.k
is greater than the middle index, recursively call findKthBit
with n-1
and length - k + 1
to find the corresponding bit in the reversed and inverted Sn-1
, and then invert the result before returning it.