data-structures · beginner · ~15 min
Single-pass linear scan with state.
Implement size_t count_distinct_sorted(const int *a, size_t n) for a sorted array.
#include <stddef.h>
size_t count_distinct_sorted(const int *a, size_t n) { /* TODO */ return 0; }
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.