Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Return the first unique value in a stream

Q273·Free·SystemVerilog

Return the first unique value in a stream

Difficulty
Easy
Topic
Data Structures
Language
SV
Interview prompt

Question

Process a stream of integers and return the earliest value whose current occurrence count is exactly one.

Starting point

Question code

class FirstUnique;
  function void push(int x);
  function bit first_unique(output int x);
endclass
Reviewed example

Trace one case

Input
push sequence=[2,3,2,4,3]
Expected output
first unique after each push=[2,2,3,3,4]

Duplicated values remain in the order queue until they reach its head, where lazy cleanup exposes the earliest surviving singleton.

What to cover

Requirements

  1. Increment a count for every push.
  2. Append a value to the order queue only on its first occurrence.
  3. Lazily remove duplicated values from the queue head.
  4. first_unique(x) returns 0 when no unique value remains and leaves x unspecified in that case.
Exact question handoffPractice Q273

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

  • Data Structures
  • SystemVerilog
  • Stream
  • Frequency map
Firmware interview questions →
Continue practicing

Related questions

Q229 · Data StructuresMaintain the top-K most frequent stream values→Q167 · Data StructuresTrack top-K frequencies in a sliding window→Q289 · ArraysRemove duplicates while preserving order→
ASIC.FYI · Learn silicon end to end.info@asic.fyi