Q289FreeSystemVerilog
Remove duplicates while preserving order
Interview prompt
Question
Remove duplicate integers from a sequence while preserving the first occurrence of every value in its original order.

Starting point
Question code
function automatic void remove_duplicates(ref int in[$], ref int out[$]);Reviewed example
Trace one case
Input
values=[3,1,3,2,1,4]Expected output
[3,1,2,4]Only the first occurrence of each integer is emitted, so the original encounter order is preserved.
What to cover
Requirements
- Clear any previous output.
- Emit a value only on its first appearance.
- Preserve first-occurrence ordering.

