LeetCode ยท Math & Bits

Math & Bit Manipulation Problem Set

XOR tricks, bit counting, matrix rotation, and integer arithmetic. These problems test mathematical insight more than data structure knowledge.

DifficultyPatternProblemKey Insight
EasyXORLC 136 ยท Single NumberXOR all elements. Duplicates cancel out. O(n).
Easybit-countLC 191 ยท Number of 1 Bitsn & (n-1) clears lowest set bit. Count iterations. O(32).
EasyreverseLC 190 ยท Reverse BitsExtract LSB, shift into result. 32 iterations. O(1).
EasymathLC 268 ยท Missing NumberXOR [0..n] with array, or use sum formula. O(n).
EasyDP+bitsLC 338 ยท Counting Bitsdp[i] = dp[i >> 1] + (i & 1). O(n).
MediummathLC 7 ยท Reverse IntegerPop digits with mod/div, check overflow before push. O(log n).
MediummatrixLC 48 ยท Rotate ImageTranspose + reverse each row. In-place. O(nยฒ).
MediummatrixLC 73 ยท Set Matrix ZeroesUse first row/col as markers. O(1) extra space. O(mยทn).
Mediumbit-opsLC 371 ยท Sum of Two IntegersXOR for sum without carry, AND + shift for carry. Repeat until no carry. O(32).

โ† Back to all LeetCode categories