The Unique Number of Occurrences interview question asks you to check if the frequency of each element in an array is unique. For example, if '1' appears 3 times and '2' appears 2 times, the occurrences are unique (3 and 2). However, if '1' appears 3 times and '2' also appears 3 times, the occurrences are not unique.
This Unique Number of Occurrences coding problem is a frequent warm-up question at companies like Apple, Uber, and Adobe. It tests your ability to use two-step data processing: first counting frequencies and then checking those counts for duplicates. It’s a great way to verify that a candidate understands how to use multiple Hash Tables or Sets in conjunction.
The standard Array, Hash Table interview pattern for this problem involves two collections. First, you use a Hash Map (or frequency array) to count how many times each number appears in the input. Second, you take all the values (the counts) from that Map and insert them into a Hash Set. If the size of the Set is equal to the number of entries in the Map, it means all counts were unique.
Suppose the array is [1, 2, 2, 1, 1, 3].
[3, 2, 1].{3, 2, 1}.[1, 2], both have a count of 1. The Set would only have one element {1}, so you would return false.Candidates sometimes forget to check the counts and instead check the numbers themselves. Another mistake is trying to sort the array and count in a single pass without a second data structure, which can be done but is often more bug-prone than the simple two-step Map-and-Set approach.
Get comfortable with "Map of counts" logic. It is the building block for dozens of interview problems. Practice transitioning from a Map's keys to its values, as this problem specifically focuses on the properties of the values.