Skip to content

Bit Manipulation problems,
and the tell.

The problem mentions powers of two, pairs that cancel, subsets, or a fixed small number of flags. 121 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. The problem mentions powers of two, pairs that cancel, subsets, or a fixed small number of flags.

The mechanism. XOR cancels duplicates, AND with n minus one clears the lowest set bit, and a bitmask of up to about 20 items fits in one integer, which turns a set into a number you can loop over.

What goes wrong. Shifting by more than the width of the type, and signed right shift carrying the sign bit in.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Number of 1 BitsEasyasked at 5 companies
  2. Complement of Base 10 IntegerEasyasked at 2 companies
  3. Maximize the Number of Partitions After OperationsHardasked at 2 companies
  4. The Number of Good SubsetsHardasked at 2 companies
  5. Construct the Minimum Bitwise Array IEasyasked at 1 companies
  6. Construct the Minimum Bitwise Array IIMediumasked at 1 companies
  7. Number ComplementEasyasked at 1 companies
  8. Find Longest Awesome SubstringHardasked at 1 companies
  9. Find if Array Can Be SortedMediumasked at 1 companies
  10. Sum of Two IntegersMediumasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About bit manipulation problems.

Free to start, no card.

Start practising
How do I know a problem is a bit manipulation problem?

The problem mentions powers of two, pairs that cancel, subsets, or a fixed small number of flags.

How many bit manipulation problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 121, split roughly 27 easy, 51 medium and 43 hard in the sample we show, so work up rather than across.

What goes wrong most often in bit manipulation problems?

Shifting by more than the width of the type, and signed right shift carrying the sign bit in.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.