LeetCode Problem 1207
Link of the Problem to try -: Link
Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= arr.length <= 1000-1000 <= arr[i] <= 1000
Solution:
It is a little bit tricky question as it says you have to return true if the elements frequency contained by the array is distinct and no frequency is same if it is then return true otherwise false. So for solving this we can use HashMap to make frequency of each element then we will create a Set and store all the values of HashMap elements in the Set and then we will simply compare sizes of both Map and Set as we know that if each element frequency is unique then the sizes are same otherwise size are not same and that is a key point to solve this question very easily.




