Counting Without a Slot per Item

Medium data structure and algorithm practice puzzle.

To count how often each item appears in a huge stream, a hash map needs an entry per item. A count-min sketch needs only a small fixed grid. Here it has two rows of width counters. An item x adds 1 to row one at slot x modulo width, and to row two at slot x divided by 3, rounded down, modulo width. Different items can land on the same counter, so a counter may be too high but never too low. Return the smaller of the query's two counters.

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 Trip Session Roll-up, a pipeline you can run and download. See every Software Engineer project.

More Computer Science puzzles

All 32 Computer Science practice problems

Browse all 676 puzzles