First Unique Number

Medium · Queue & Deque · about 20 minutes

Asked at Uber, Amazon, Bloomberg, Google.

Track the first unique integer in a queue that keeps growing.

  • FirstUnique(nums) initializes the queue with nums.
  • showFirstUnique() returns the first (oldest) value that appears exactly once so far, or -1.
  • add(value) appends value to the queue.

Related guides