Choose the algebra from what may disappear

An array has pairs and one singleton. A frequency map works.

Decision: Which fixed-size summary can erase pairs in any order? Does the same summary erase triples?

1 / 9

Add Binary — predict before coding

A carry is the complete information one bit position needs from lower positions. Working from the right avoids converting an arbitrarily long input into a fixed-width integer.

Decision: Add 10111 and 00101. After the first two low positions, emitted bits are 00 and carry is 1. Complete the next column, including its outgoing carry, then finish the result. Why would resetting carry before using it fail?

2 / 9

Reverse Bits — predict before coding

Fixed width is the point. Reversing only the significant binary digits of 1 would return 1, but reversing all 32 positions places that bit at position 31.

Decision: A byte-oriented implementation reverses the eight bits inside each byte but leaves byte order unchanged. On uint32(1), it returns 0x00000080. What second transformation repairs full 32-bit reversal, and why?

3 / 9

Number of 1 Bits — predict before coding

Subtracting one flips the lowest set bit to zero and every lower zero to one. AND with the original keeps higher bits and clears exactly that lowest set bit.

Decision: A proposed test checks HammingWeight(x)+HammingWeight(^x)==32 for uint32 inputs. A broken implementation always returns 16. Would it pass, and what independent exact cases should accompany that property?

4 / 9

Single Number — predict before coding

XOR is a cancellation operation over each bit position. Commutativity lets equal pairs cancel even when their occurrences are far apart in the input.

Decision: Both [0,4,4] and [1,2,3] have total XOR zero. Does a zero result prove that a valid singleton zero exists? Explain what the algorithm assumes instead of checking.

5 / 9

Single Number II — predict before coding

Replace pair cancellation with per-bit counting modulo three. A triplicated value contributes either zero or three to every bit count, leaving only the singleton’s bit pattern.

Decision: While reading [6,6,6,-1], after the first two entries some bit-count residues equal 2. Are those residues already the singleton’s bits? Identify when cancellation becomes a valid reconstruction argument.

6 / 9

Bitwise AND of Numbers Range — predict before coding

The inclusive range preserves only the common high-bit prefix of its endpoints. Below their highest differing position, the interval necessarily crosses a binary boundary that clears those suffix bits.

Decision: Change the input from a contiguous interval to the sparse set {9,11}. Its smallest and largest values have common prefix 10 in four-bit notation. Would zeroing the suffix still compute the set’s AND?

7 / 9

Change the multiplicity promise

In [4,9,2,4,2,7], exactly two values occur once.

Total XOR is 14. Why is that not an answer? Use one set bit to derive two solvable groups.

8 / 9

Reconstruct and transfer

Reconstruct each algorithm from its invariant.

Check width, sign, multiplicity assumptions, and output formatting separately.

9 / 9
←/→ or click edges to navigate · ? help · N notes · F fullscreen