call(back)
Algorithms & Data Structuresmedium

List Unallocated Experiment Buckets

Same bucket space [0, n). Existing experiments hold ranges of buckets, given as inclusive [start, end] pairs — possibly overlapping, possibly out of bounds (clamp them), and in no particular order. Return the unallocated buckets as a minimal sorted list of inclusive [start, end] ranges (adjacent free buckets merge into one range).

unallocatedRanges(10, [[2, 4], [6, 6]])  ->  [[0, 1], [5, 5], [7, 9]]

Asked at