Intermediate Bit Manipulation Problems for Coding Interviews
51 intermediate Bit Manipulation problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 51 intermediate and 0 advanced. The companies that ask them most often are Google, Amazon, Bloomberg, Microsoft.
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
- Counting Bits (Intermediate)
- Reverse Integer (Intermediate)
- Bitwise AND of a Range (Intermediate)
- Longest XOR Subarray (Intermediate)
- Count Subsets With Given XOR (Intermediate)
- Maximum Width of Binary Tree (Intermediate)
- String to Integer (Intermediate)
- Evaluate Reverse Polish Notation (Intermediate)
- Basic Calculator II (Intermediate)
- Super Ugly Number (Intermediate)
- Gray Code (Intermediate)
- Total Hamming Distance (Intermediate)
- Divide Two Integers (Intermediate)
- Design Bitset (Intermediate)
- UTF-8 Validator (Intermediate)
- Chalkboard XOR Game (Intermediate)
- Longest Nice Subarray (Intermediate)
- Shortest Subarray With OR at Least K (Intermediate)
- XOR Queries of a Subarray (Intermediate)
- Score After Flipping Matrix (Intermediate)
- Sum of Two Integers Without Plus (Intermediate)
- Bitwise ORs of Subarrays (Intermediate)
- Minimum Flips to Make a OR b Equal to c (Intermediate)
- Concatenation of Consecutive Binary Numbers (Intermediate)
- Maximum XOR After Operations (Intermediate)
- Minimize XOR (Intermediate)
- Bitwise XOR of All Pairings (Intermediate)
- Largest Combination With Positive AND (Intermediate)
- Smallest Number With Exactly N Divisors (Intermediate)
- Probability of No Adjacent Ones in Random Bits (Intermediate)
- Total Set Bits From One to N (Intermediate)
- Next Higher Number With Same Set Bits (Intermediate)
- Previous Lower Number With Same Set Bits (Intermediate)
- Sum of Pairwise Bitwise AND (Intermediate)
- Sum of Pairwise Bitwise XOR (Intermediate)
- Longest Subarray With Nonzero AND (Intermediate)
- Count Pairs With XOR Equal to K (Intermediate)
- Minimum XOR of Any Pair (Intermediate)
- Base64 Encode String (Intermediate)
- Elementary Cellular Automaton Population (Intermediate)
- Count Binary Numbers With Equal Zeros and Ones (Intermediate)
- Set Bits Total in a Range (Intermediate)
- Bitwise OR of a Range (Intermediate)
- Pairs With AND At Least XOR (Intermediate)
- Subarrays With Zero XOR (Intermediate)
- XOR of All Subarray XORs (Intermediate)
- Sum of XOR of All Subsets (Intermediate)
- Sum of AND Over All Subsets (Intermediate)
- Smallest Number With Given Digit Sum and Length (Intermediate)
- Pairs With XOR Equal K (Intermediate)
- Evil Numbers in a Range (Intermediate)
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.