Basic Bit Manipulation Problems for Coding Interviews
33 basic Bit Manipulation problems from real coding interviews, each with test cases you can run online. By difficulty they split into 33 basic, 0 intermediate and 0 advanced. The companies that ask them most often are Google, Amazon, Bloomberg, Meta.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Number of One Bits (Basic)
- Hamming Distance (Basic)
- Decode XORed Array (Basic)
- Counting Bits (Basic)
- Minimum Operations on Binary String (Basic)
- Boolean Parenthesization Count (Basic)
- Binary Linked List to Integer (Basic)
- Sum of Root-to-Leaf Binary Numbers (Basic)
- Sort Integers by Number of 1 Bits (Basic)
- Complement of Base 10 Integer (Basic)
- Elias Gamma Encoding (Basic)
- Varint Encoding (Basic)
- Minimum Suffix Flips (Basic)
- Reverse Bits (Basic)
- Binary Number With Alternating Bits (Basic)
- Prime Number of Set Bits (Basic)
- XOR Operation in an Array (Basic)
- Original Array From Prefix XOR (Basic)
- Neighboring Bitwise XOR (Basic)
- Gray Code of Index (Basic)
- XOR of Numbers From One to N (Basic)
- XOR of a Range of Numbers (Basic)
- Binary Index From Gray Code (Basic)
- Position of K-th Set Bit (Basic)
- Binary Coded Decimal Encoding (Basic)
- Pairs With Equal Popcount (Basic)
- Rotate Bits Left Within Width (Basic)
- Sum of Trailing Zero Counts (Basic)
- Swap Two Bits of a Number (Basic)
- Bit Reversal Index (Basic)
- Alternating Bit Numbers Count (Basic)
- Binary Reflected Gray Code (Basic)
- Inverse Gray Code (Basic)
Related
Frequently asked questions
How do I get good at bit manipulation problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run bit manipulation problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.