Determine whether every distinct value in an array occurs a unique number of times.
Given an integer array, count how many times each distinct value appears. Return whether all occurrence counts are different from one another.
In other words, no two distinct values should have the same frequency in the array.
Input Format
- An integer array
arr. - The array may contain positive, negative, or zero values.
Output Format
- Return
trueif the frequency of every distinct value is unique. - Otherwise, return
false.
Constraints
- Use the array as given; do not reorder or modify the logical meaning of the elements.
- The array may be empty.
- A linear-time solution is expected.
Example 1
Input
arr = [1,2,2,1,1,3]
Output
true
Explanation
Frequencies are 1→3, 2→2, and 3→1. All counts are distinct.
Example 2
Input
arr = [1,2]
Output
false
Explanation
Both 1 and 2 appear once, so the frequency 1 is repeated.
Show 1 more example
Example 3
Input
arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output
true
Explanation
Frequencies are -3→3, 0→2, 1→4, and 10→1. No two values share the same count.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.