Hardware interview practice
Coalesce a frame of DMA ranges
Buffer one frame of up to eight half-open direct-memory-access (DMA) ranges, sort them by start then end, and emit the smallest sorted set covering the same addresses. Merge overlap and exact adjacency.
Reviewed example
Work through one case
Input
input half-open ranges=[10,20),[5,8),[8,10),[15,25)Expected output
one output range=[5,25) with out_last=1Sorting places [5,8) first; exact adjacency at 8 and 10 plus overlap at 15 coalesce every range into one cover.
What to cover
Requirements
- Accept 1 through 8 valid ranges satisfying start < end before producing output.
- Interpret ranges as [start, end) and merge whenever next_start <= current_end.
- Handle arbitrary order, duplicate starts, contained ranges, and adjacent ranges deterministically.
- Assert out_last only with the final coalesced token and hold every output field stable while stalled.
