Verification #47 · 2026-11-09 · Dynamic arrays · Easy · about 10 min

The buffer that forgets when it grows

growbuf is a small growable buffer of int unsigned, kept in a dynamic array data. count is how many values were pushed.

  • push(v) appends v. When the array is full, its size doubles first.
  • reserve(n) makes sure data holds at least n elements. If it already does, nothing changes.
  • Whenever the array is resized, every value pushed so far must still be there at the same index, and get(i) returns it.

Pushing a few values works, but a longer run returns the wrong data. Fix growbuf.sv.

Write and run your answer in the browser. The hidden tests check it, and it’s free.