Practice Discrete Math

Algorithms / Bit Mixed Interview

Least You Need to Know: Bit Reasoning Depth and Mixed Interview Drills

This tranche pushes bit reasoning one step further, then mixes it with asymptotics, graphs, and invariants the way interview questions often do.

The least you need to know

Key notation

x & (x-1) clear lowest set bit
1 << k mask with only bit k set
[lo, hi] current candidate interval

Tiny worked example

  • For positive `x=16`, the binary form is `10000`.
  • Then `x-1 = 01111`, so `x & (x-1) = 0`.
  • That is why the trick detects powers of two.
  • In the same interview round, you might also need to explain why binary search is logarithmic or why BFS discovers shortest paths layer by layer.

Common mistakes

How to recognize this kind of problem

Start practice