315. Unique Number of Occurrences

Easy
Frequency Uniqueness
Hashing

Problem

Given an array of integers arr, return true if the number of occurrences of every distinct value is unique. Otherwise return false.

Examples

Example 1

Input: [1,2,2,1,1,3]
Output: true

Example 2

Input: [1,2]
Output: false

Example 3

Input: [-3,0,1,-3,1,1,1,-3,10,0]
Output: true
Constraints

1 <= arr.length <= 1000

-1000 <= arr[i] <= 1000

Hints

?? First compute the frequency of each value.

?? Then determine whether any two values have the same frequency.

?? A set of frequencies makes the second step simple.

Expected Complexity
Time: O(n)
Space: O(n)
Follow-up

Can you solve it without sorting the frequencies?

Practice Notes

Attempts: 0

Time spent: 0min

Hints used: 0

00:00
Loading...
Case 1
Case 2
Case 3
Input
[1,2,2,1,1,3]
Expected
true