Free Bits in Every Pointer

Easy data structure and algorithm practice puzzle.

Memory allocators hand out addresses that are multiples of 8, so the lowest three bits of every pointer are always zero. Language runtimes use those three bits to store a small tag, such as the type of the value, right inside the pointer. Given an address and a tag, return the tagged pointer, which is the two combined with OR. Return -1 if the address is not a multiple of 8 or the tag is not between 0 and 7, since either would corrupt the other.

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 Reading Flag Store, a pipeline you can run and download. See every Software Engineer project.

More Computer Memory puzzles

All 14 Computer Memory practice problems

Browse all 676 puzzles