DescriptionQ273
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);
endclassExample input and output
Use this case to check your interpretationInput
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.
