One Question per Bit

Easy data structure and algorithm practice puzzle.

An oracle hides an n-bit secret. Ask it about any number x and it answers 1 if x and the secret share an odd number of 1 bits, and 0 otherwise. You are given its answers for every x from 0 up, as a table. A classical computer finds the secret by asking about 1, 2, 4 and so on, one question per bit, because each of those singles out one bit of the secret. Return the secret. A quantum computer learns all n bits with a single question.

Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free to play, with no account.

Every line of the solution comes with a note explaining why it is there, and a step by step replay shows the code running. At level 3, where you type it yourself, you can ask for an AI mock interview on this problem that ends with a hiring manager's scorecard.

Then grow it into a real project with the Software Engineer button: this puzzle becomes the Shot Flag Store, a pipeline you can run and download. See every Software Engineer project.

More Quantum Computing puzzles

All 20 Quantum Computing practice problems

Browse all 676 puzzles