pointers-memory · intermediate · ~15 min
Model alloc/free balance — the essence of leak-freedom.
Given an operation trace where 'a' = allocate and 'f' = free, implement int balanced_allocs(const char *ops) returning 1 if every allocation is eventually freed and no free happens without a live allocation (depth never goes negative, ends at 0).
int balanced_allocs(const char *ops) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.