Nth number with same number of 1 bit’s set

There is a sequence of increasing numbers that have the same number of
binary 1’s in them. Given n, the number of 1 bits set in each number, write an algorithm
to find the n’th number in the series.

it is a simple BFS problem. say n=3. insert 111 into queue initially.The states which we need need to push into the queue once we pop a number from queue are the numbers which have just one zero more. So suppose the number u popped from queue is 1011. Then into the queue we need to push 10011,10101,10110.Also we need to keep track of which states we have visited,

Leave a Reply

Your email address will not be published. Required fields are marked *