Master bit manipulation — XOR tricks, Brian Kernighan, bitmask DP, power checks. 40+ problems with O(1) solutions. FAANG interview essential.
Built by Kushagra Bansal | Founder @ Project Lab India
- Master all bitwise operators:
&,|,^,~,<<,>> - Solve problems in O(1) that normally take O(n)
- Implement Brian Kernighan, XOR swap, power-of-two checks
- Apply bitmask DP for subset problems
| # | Topic | Trick | Frequency |
|---|---|---|---|
| 1 | XOR Tricks | a^a=0, a^0=a | ⭐⭐⭐⭐⭐ |
| 2 | Count Set Bits | Brian Kernighan: n&(n-1) | ⭐⭐⭐⭐⭐ |
| 3 | Power of Two | n&(n-1)==0 | ⭐⭐⭐⭐⭐ |
| 4 | Bit Masking | mask=(1<<k) | ⭐⭐⭐⭐ |
| 5 | Set/Clear/Toggle | OR/AND-NOT/XOR | ⭐⭐⭐⭐ |
| 6 | Bitmask DP | 2^n subsets | ⭐⭐⭐⭐ |
See notes/learning_notes.md for full complexity analysis.
git clone https://github.com/kushagrabansal-IOT/DSA-Bit-Manipulation-Lab.git
cd DSA-Bit-Manipulation-Lab
python solutions/main.py
python -m pytest tests/ -vDSA-Bit-Manipulation-Lab/
├── solutions/
│ └── main.py ← All solutions (run this)
├── tests/
│ └── test_main.py ← pytest test suite
├── notes/
│ └── learning_notes.md
├── LICENSE
└── README.md
- Add C++ / Java implementations
- Add LeetCode links for all problems
- Add visual diagrams
- Add more advanced variants
Kushagra Bansal — Founder @ Project Lab India, Jaipur 🔬 DSA • OOPS • DBMS • IoT • Competitive Programming 🏆 Innovation Award Recipient • IEEE Member 🛒 radiomarket.in
MIT License — See LICENSE
⭐ Star if it helped! | 🍴 Fork it | 📢 Share it