You are given two integers N and K. Determine the Nth smallest integer with K set bits in its binary representation. Since the answer may be very large print the answer modulo 10e9+7.
Notes:
• A bit at a particular position in the binary representation of an integer is said to be set if its value is 1.
• The integer N can be very large so it has been provided as a string in the input.
Example:
Assumptions:
• N = 4
• K = 2
Approach:
The numbers with 2 set bits are 3, 5, 6, 9, 12.
Therefore the 4th smallest integer with 2 set bits is 9.
Function description:
Complete the solve function provided in the editor. This function takes the following 2 parameters and returns the Nth smallest integer with K set bits modulo 10e9+ 7:
N: Represents a string denoting the integer N
K: Represents an integer denoting the required number of set bits
1<=K<=60
1<=N<=10^(K+1)