Quant Memo
Coding/●●●●●

Even or odd set bits for every number up to n

For every integer i from 0 to n, output 1 if i has an odd number of 1-bits and 0 if it has an even number (its "bit parity").

n = 5
-> [0, 1, 1, 0, 1, 0]   # 0=even, 1=odd, 2(=10)=odd, 3(=11)=even, 4(=100)=odd, 5(=101)=even

Return the full parity table in O(n)O(n) total, not by counting each number's bits from scratch.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions