Find Nth Smallest Integer With K One Bits
You are given two positive integers n and k.
Return an integer denoting the n^th smallest positive integer that has exactly k ones in its binary representation. It is guaranteed that the answer is strictly less than 2^50.
Example 1
Input
n = 4, k = 2Output
9The 4 smallest positive integers with exactly 2 ones in binary are 3, 5, 6, and 9, so the answer is 9.
Example 2
Input
n = 3, k = 1Output
4The 3 smallest positive integers with exactly 1 one in binary are 1, 2, and 4, so the answer is 4.
Constraints
- 1 <= n <= 2^50
- 1 <= k <= 50
- The answer is strictly less than
2^50.