Count distinct values in a sorted array

0
Remix

Count the distinct values in a sorted array of length n that holds only k distinct values, where k is much smaller than n. A linear scan works; do better by jumping over each run of equal values with binary search, in about O(k log n), and explain when that wins.

MetaCodingLast asked Mar 2026
No answer yet. Write the first one; the best answer gets endorsed.