data-structures · beginner · ~15 min
Use modular arithmetic for wrap-around indexing.
A queue backed by a ring buffer of capacity cap wraps around. Implement int ring_index(int start, int k, int cap) returning the buffer index k positions after start (0 <= start < cap, k >= 0).
int ring_index(int start, int k, int cap) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.