Kick Out the Occupant

Hard data structure and algorithm practice puzzle.

Cuckoo hashing gives every key two homes, one in each of two tables, so a lookup checks two slots and is done. A key's slot in the first table is key modulo size, and in the second it is key divided by size, rounded down, modulo size. To insert, put the key in its first-table slot. Whatever was there is kicked out to its slot in the other table, and so on. Return the first table then the second, with -1 for empty, or an empty list if one insert needs too many moves.

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 Search Index, 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