DSA · Bit Manipulation· Part 32 of 32
Bit Manipulation Capstone Practice
The final step is mixed practice. Real interviews and contests do not announce "use lowbit" or "this is SOS DP." Your job is to recognize the pattern from constraints, operations, and edge cases.
How to Practice
- Read the statement and write down the bitwise operation involved.
- Identify whether the problem is about one value, a pair, a subset, a range, or all masks.
- Estimate constraints and map them to the catalog.
- Solve first, then compare with a second approach if one exists.
- Write down the invariant in one sentence.
Level 1: Interview Fundamentals
- LC 136 - Single Number XOR cancellation
- LC 191 - Number of 1 Bits popcount
- LC 231 - Power of Two single bit
- LC 190 - Reverse Bits fixed width
- LC 461 - Hamming Distance XOR + popcount
Level 2: Interview Mediums
- LC 137 - Single Number II bit columns
- LC 260 - Single Number III lowbit partition
- LC 371 - Sum of Two Integers XOR carry
- LC 393 - UTF-8 Validation byte masks
- LC 201 - Bitwise AND of Numbers Range common prefix
Level 3: Core Competitive Programming
- CSES - Range Xor Queries prefix XOR
- CSES - Elevator Rides bitmask DP
- CSES - Hamiltonian Flights path DP
- CSES - Money Sums bitset knapsack
- CSES - Gray Code construction
Level 4: Advanced CP
- CSES - Bit Problem SOS DP
- LC 1803 - Count Pairs With XOR in a Range binary trie counting
- CF 845G - Shortest Path Problem? XOR linear basis
- CF 165E - Compatible Numbers superset DP
- AtCoder ABC212 H - Nim Counting FWT
Final Cheat Sheet
x & -x // isolate lowest set bit
x & (x - 1) // clear lowest set bit
x ^ y // differing bits / parity difference
pref[r+1] ^ pref[l] // range XOR
for (sub=m; sub; sub=(sub-1)&m) // enumerate submasks
dp |= dp << w // bitset subset sum
x ^ (x >> 1) // binary to Gray
ans = max(ans, ans ^ basis[b]) // maximize XOR with linear basis
Completion Standard
You are ready for bit manipulation in interviews if you can explain the invariant for every Level 1 and Level 2 problem without memorizing code. You are ready for serious CP if you can also choose between binary trie, linear basis, SOS DP, FWT, and bitset optimization from constraints alone.