Practice Discrete Math

Algorithms / Bitmask Set

Least You Need to Know: Bitmasks as Sets, Flags, and Small-State Compression

A bitmask can represent membership in a small universe using one integer. This lets interviews compress sets, feature flags, visited states, and eligibility rules into fast bitwise operations.

The least you need to know

Key notation

mask integer whose bits encode membership
1 << i mask containing only item i
A & B items present in both masks

Tiny worked example

  • Suppose bits 0 through 4 represent required skills.
  • A candidate mask stores which skills are present.
  • To test for skill 3, compute `mask & (1 << 3)`.
  • To add skills from another source, OR the masks together.

Common mistakes

How to recognize this kind of problem

Next recommended lesson

Continue through this topic with Least You Need to Know: AND, OR, XOR, and Single-Bit Updates.

Least You Need to Know: AND, OR, XOR, and Single-Bit Updates

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

Start practice