You have a queue of integers, and you need to retrieve the first unique integer in the queue.
Implement the FirstUnique class:
FirstUnique(int[] nums) Initializes the object with the numbers in the queue.int showFirstUnique() Returns the value of the first unique integer in the queue, or -1 if there is no unique integer.void add(int value) Inserts value into the queue.
A number is unique if it appears exactly once among all numbers currently in the queue.FirstUnique firstUnique = new FirstUnique([2, 3, 5]); firstUnique.showFirstUnique(); // return 2 firstUnique.add(5); // the queue is now [2, 3, 5, 5] firstUnique.showFirstUnique(); // return 2 firstUnique.add(2); // the queue is now [2, 3, 5, 5, 2] firstUnique.showFirstUnique(); // return 3 firstUnique.add(3); // the queue is now [2, 3, 5, 5, 2, 3] firstUnique.showFirstUnique(); // return -1
Reported as a LeetCode-style design question for software engineer phone screen and onsite rounds, with discussion centered on maintaining insertion order while updating duplicate counts efficiently.