Bitmasking is a powerful technique used in algorithm design to represent sets and states using the binary representation of integers. Each bit in a number corresponds to whether an element is present or absent in a subset. This compact representation allows many subset and state-based problems to be solved efficiently, especially when the number of elements is small (typically ≤ 20).
In coding interviews, bitmasking often appears in problems involving subset enumeration, state compression, and optimization. Instead of storing sets explicitly, developers can use bit operations such as AND, OR, XOR, and bit shifts to manipulate states quickly. These operations are fundamental concepts from Bit Manipulation and are frequently combined with advanced techniques like Dynamic Programming for solving complex problems such as traveling salesman variations or assignment problems.
Common patterns you’ll encounter include:
Practicing bitmask problems helps you develop a deeper understanding of binary operations and efficient state modeling—skills that are highly valued in technical interviews.
Bitmasks are frequently used to optimize backtracking solutions by tracking used elements or states efficiently.
Helps understand subset generation and counting problems that are often modeled using bitmasks.
Bitmasking relies on bitwise operations such as AND, OR, XOR, and bit shifts to represent and manipulate subsets efficiently.
Many advanced bitmask problems use DP with state compression to represent visited subsets or configurations.
| Status | Title | Video | Leetcode | Solve | Difficulty | Companies | Topics |
|---|---|---|---|---|---|---|---|
| 351. Android Unlock Patterns | Solve | Medium | Microsoft+1 | ||||
| 464. Can I Win | Solve | Medium | LinkedIn | ||||
| 473. Matchsticks to Square | Solve | Medium | Microsoft | ||||
| 526. Beautiful Arrangement | Solve | Medium | Cisco | ||||
| 638. Shopping Offers | Solve | Medium | Amazon+3 | ||||
| 698. Partition to K Equal Sum Subsets | Solve | Medium | Amazon+2 | ||||
| 1066. Campus Bikes II | Solve | Medium | Amazon+1 | ||||
| 1947. Maximum Compatibility Score Sum | Solve | Medium | Facebook | ||||
| 1986. Minimum Number of Work Sessions to Finish the Tasks | Solve | Medium | Google+3 | ||||
| 2002. Maximum Product of the Length of Two Palindromic Subsequences | Solve | Medium | Ascend+2 | ||||
| 2152. Minimum Number of Lines to Cover Points | Solve | Medium | Morgan Stanely | ||||
| 2184. Number of Ways to Build Sturdy Brick Wall | Solve | Medium | Google | ||||
| 2305. Fair Distribution of Cookies | Solve | Medium | Amazon | ||||
| 2572. Count the Number of Square-Free Subsets | Solve | Medium | Media.Net | ||||
| 2741. Special Permutations | Solve | Medium | - | ||||
| 2992. Number of Self-Divisible Permutations | Solve | Medium | - |
Frequently appear alongside Bitmask.
Common questions about Bitmask.
Typical problems include subset enumeration, traveling salesman variations, assignment problems, and tracking visited states in dynamic programming.
Bitmasking enables efficient solutions for subset, permutation, and state-compression problems. Interviewers often use it to test knowledge of bit operations and optimization techniques.
A bitmask is an integer used to represent a set of elements where each bit indicates whether an element is present. It allows fast set operations using bitwise operators.
Bitmasking is ideal when the number of elements is small and you need to represent subsets efficiently. It is particularly useful when combined with dynamic programming or exhaustive search.
Practicing 30–50 well-chosen problems is usually enough to understand common patterns. The 47 problems in this collection provide strong coverage of typical interview scenarios.