Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ273
Page ↗
Q273FWASIC interview problem

Return the first unique value in a stream

TechniquesSystemVerilogStreamFrequency mapLazy queue
DifficultyEasy
TopicData Structures
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

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

Class declarationSystemVerilog
class FirstUnique;
  function void push(int x);
  function bit first_unique(output int x);
endclass

Example input and output

Use this case to check your interpretation
Input
push sequence=[2,3,2,4,3]
Output
first unique after each push=[2,2,3,3,4]
Explanation

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

02

Requirements (4)

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