When N <= ~22, bitmasks enumerate the 2^N subsets in O(2^N). The bit at position i is 1 if element i is in the subset. Bitwise AND tests intersection, OR tests union, XOR toggles membership. Use it for meet-in-the-middle, set cover, DP over subsets.
Iterate subsets: for mask in range(1<<N): for i in range(N): if mask >> i & 1: …
Subset DP: dp[mask] = optimal answer using elements indicated by mask.
Interview bitmask problem: partition array into two equal-sum subsets.
[a b c d]
0000 0001 0010 0011 ... 1111
iterate all subsets in O(2^N)
Bitmask for small N, large subset count; prefer sum-of-subset DP when SUMs are bounded.