Hardware interview practice
Sort intervals by start and end
Sort a queue of address intervals by start address, then by end address when starts are equal.
Reviewed example
Work through one case
Input
intervals = [(4, 8), (1, 5), (1, 3)]Expected output
[(1, 3), (1, 5), (4, 8)]The start value is the primary key and the end value breaks ties deterministically.
What to cover
Requirements
- Sort in ascending unsigned address order.
- Use end_addr only as the tie-breaker.
- Do not combine fields into an overlapping arithmetic key.
