You manage an integer ID space [0, 999] and N named buckets in a fixed order. Implement two operations:
(
-
allocate(buckets: List<(name, desired_size)>) -> List<(name, start_id, end_id)> that assigns contiguous, non-overlapping ranges to buckets from low to high IDs, preserving the given order, and fails if the sum of desired sizes exceeds 1000;
(
-
resize(name, new_desired_size) that grows or shrinks the specified bucket’s range and minimally shifts only adjacent ranges while keeping all ranges contiguous, disjoint, in order, and within [0, 999]; if the total desired size exceeds capacity, return a clear error. Define the data structures, APIs, and time/space complexity, and describe how you would test boundary cases such as empty buckets, full utilization, and expansions that would overflow capacity.