Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Remove duplicates while preserving order

Q110·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.
Candidate starting point

Implementation scaffold

function automatic void remove_duplicates(
  ref int in[$],
  ref int out[$]
);
  bit seen[int];
  int snapshot[$];
  // Implement here: keep first occurrences in encounter order.
endfunction
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.
  4. The same queue variable may be passed as input and output; snapshot its original values before clearing output.
Exact question handoffPractice Q110

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

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Firmware Guide

Review algorithms, data structures, fixed-memory reasoning, concurrency, and silicon bring-up.

  • Arrays
  • SystemVerilog
  • Deduplication
  • Associative set
Firmware Guide →
Continue practicing

Related questions

Q169 · Data StructuresInsert, remove, and sample in average O(1)Medium→Q326 · SystemVerilog & UVMMatch out-of-order analysis streams by transaction IDHardP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi