data-structures · intermediate · ~15 min

Find a free slot (linear probing)

Implement linear probing with wrap-around.

Challenge

An open-addressing table uses 0 to mean an empty slot. Implement int find_slot(const int *table, int cap, int start) returning the index of the first empty slot scanning from start and wrapping, or -1 if the table is full.

Starter code

int find_slot(const int *table, int cap, int start) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.