Bit manipulationAnimated
Bitmasking
Store a set of flags in the bits of an integer.
Time
O(1) per op
Extra space
O(1)
Use it for
Compact sets and DP states.
How it works
- A bitmask packs many yes/no flags into one integer: bit i is flag i.
- Set bit i: n | (1 << i). Clear bit i: n & ~(1 << i).
- Toggle bit i: n ^ (1 << i). Check bit i: (n >> i) & 1.
- Used for compact sets, permissions, and DP states.
Watch it run
Loading animation…