First Unique Number in Data Stream Problem
First Unique Number in Data Stream Problem — ExecCode Medium DSA Practice
Solve the First Unique Number in Data Stream problem on ExecCode. Free online medium DSA practice in Design. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You have a queue of integers. You need to support adding integers to the queue and finding the first unique integer in the queue. Implement FirstUnique class with FirstUnique(nums), add(value), and showFirstUnique().
Examples
Input nums = [2, 3, 5], ops = ["show", 5, "show", 2, "show", 3, "show"]; Output [2, 2, 3, -1]. Input nums = [1, 2, 1], ops = ["show", 2, "show"]; Output [2, -1]. Input nums = [4, 5, 4], ops = ["show", 6, "show"]; Output [5, 5]
Constraints
1 ≤ nums.length ≤ 10⁵ 1 ≤ nums[i], value ≤ 10⁸ At most 10⁵ calls to add / showFirstUnique in interviews.
Practice First Unique Number in Data Stream free on ExecCode. Browse DSA problems, topic map, and placement guides.