Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Remove duplicates while preserving order

Q289·Free·SystemVerilog

Remove duplicates while preserving order

Difficulty
Easy
Topic
Arrays
Language
SV
Interview prompt

Question

Remove duplicate integers from a sequence while preserving the first occurrence of every value in its original order.

Input sequence annotated as new or duplicate with blank stable-order output slots
Keep the first occurrence of each value and preserve the sequence's 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

  1. Clear any previous output.
  2. Emit a value only on its first appearance.
  3. Preserve first-occurrence ordering.
Exact question handoffPractice Q289

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessA Free account unlocks the complete reviewed solution.
Continue learning

SystemVerilog

  • Arrays
  • SystemVerilog
  • Deduplication
  • Associative set
Firmware interview questions →
Continue practicing

Related questions

Q232 · ArraysForward-looking sliding window maximum→Q233 · ArraysTrailing sliding window maximum→Q218 · ArraysMerge inclusive overlapping intervals→
ASIC.FYI · Learn silicon end to end.info@asic.fyi