dsa4 min read
Binary Search Master Recap — All Patterns & Templates
Complete cheatsheet for Binary Search: all 7 patterns, the universal template, BS on answer guide, Big O reference, and MAANG priority.
Read →
1575 articles
Complete cheatsheet for Binary Search: all 7 patterns, the universal template, BS on answer guide, Big O reference, and MAANG priority.
Master bit manipulation: XOR tricks, counting bits, bitmask DP, Brian Kernighan, two's complement, and 5-language operators.
Every element appears twice except one. XOR all numbers: duplicates cancel (a^a=0), single number remains.
Every element appears 3 times except one. Track bit counts mod 3: ones and twos bitmasks, or count each bit position.
Two numbers appear once, rest appear twice. XOR all to get a^b, then use any set bit to partition numbers into two groups.