Iterating over subset of set bits

How to iterate over all subsets of set bits in a number with n bits in a time complexity not exceeding O(2^N + n^2) where N is the number of set bits?

https://cp-algorithms.com/algebra/all-submasks.html

2 Likes