What’s the best algorithm to find all binary strings of length n that contain k bits set? For example, if n=4 and k=3, there are…
0111
1011
1101
1110
I need a good way to generate these given any n and any k so I’d prefer it to be done with strings.
This method will generate all integers with exactly N ‘1’ bits.
From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation