Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Sort intervals by start and end

Hardware interview practice

Sort intervals by start and end

EasyArraysSystemVerilog

Sort a queue of address intervals by start address, then by end address when starts are equal.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
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

  1. Sort in ascending unsigned address order.
  2. Use end_addr only as the tie-breaker.
  3. Do not combine fields into an overlapping arithmetic key.
asic.fyi · Learn silicon end to end.info@asic.fyi