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 withnums.showFirstUnique()returns the first (oldest) value that appears exactly once so far, or -1.add(value)appendsvalueto the queue.