Facebook/Meta Phone Intern 2022 summer
Anonymous User
1420

use n bit number represented as a string of 0's and 1's

if n == 3,

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

then all n bit numbers (as string) are sorted by number of 1's
so the new order will be:

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

note the first column is not the decimal number of the string, is the order

output is the k'th index string

Comments (5)