Hardware interview practice
Sort only a subrange
Sort only the inclusive range [left, right] of a dynamic integer array in ascending order.
Reviewed example
Work through one case
Input
values = [9, 5, 3, 7, 1], left = 1, right = 3Expected 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
- Leave elements outside the selected range unchanged.
- Clamp the range to the legal array bounds.
- Return without work for an empty or single-element range.
