Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Sort only a subrange

Hardware interview practice

Sort only a subrange

EasyArraysSystemVerilog

Sort only the inclusive range [left, right] of a dynamic integer array in ascending order.

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
values = [9, 5, 3, 7, 1], left = 1, right = 3
Expected output
[9, 3, 5, 7, 1]

Only indices 1 through 3 are sorted; the values outside the inclusive range remain untouched.

What to cover

Requirements

  1. Leave elements outside the selected range unchanged.
  2. Clamp the range to the legal array bounds.
  3. Return without work for an empty or single-element range.
Continue practicing

Related questions

ArraysBubble sort in place→ArraysInsertion sort in place→
asic.fyi · Learn silicon end to end.info@asic.fyi