1429. First Unique Number

Problem

Implement a data structure that finds the first unique number in a stream.

Design a data structure that supports:

  • FirstUnique(nums): Initialize with a stream of numbers.
  • showFirstUnique(): Return the first unique number in the stream. If no unique number exists, return -1.
  • add(value): Add a new number to the stream.

A unique number is one that appears exactly once in the stream.

Examples
Input: [["FirstUnique","showFirstUnique","add","add","showFirstUnique","add","showFirstUnique"],[[[2,3,5]],[],[3],[3],[],[2],[]]]
Output: [null,2,null,null,2,null,5]
Hints
Related Problems

1429. First Unique Number

Implement a data structure that finds the first unique number in a stream.