find the kth number sorted by the number of 1 bits
Anonymous User
568

A question from Facebook phone interview
Give int n and int k, where n is len of bits, find the kth number if sorting those bits by the number of 1 bits. If having same number of 1 bits, sort bits based on the value

ex.
n = 3, k = 4
should return 011

0 000
1 001
2 010
3 100
4 011
5 101
6 110
7 111

Naive solution to generate and sort all bits is not accepted

Comments (7)