Hash table · Compiler

Hash table

Insert distinct integer keys into an empty table with b slots numbered 0 through b-1. A key x starts at x modulo b. While its slot is occupied, advance one slot, wrapping from b-1 to 0. Store the key in the first empty slot.

Input
The first line contains b n (1 <= n <= b <= 100). The next line contains n distinct keys in insertion order, each an integer from 0 to 10000.
Output
Print n space-separated slot indices, one for each key in insertion order.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…