Even Frequency Check
Given an array of integers, determine if all the integers have an even frequency in the array. Return 'Yes' if every integer appears an even number of times, otherwise return 'No'.
[ 2, 4, 4, 2 ]
Explanation. Both 2 and 4 appear twice in the array, which is an even count, so the output is 'Yes'.
[ 3, 3, 1, 1, 2, 2 ]
Explanation. 3, 1, and 2 all have frequencies of two, which is even.
[ 1, 2, 3, 4, 5 ]
Explanation. Each number appears exactly once, which is not an even count.
[ 10, 10, 10, 10, 10, 10 ]
Explanation. 10 appears six times, which is an even count.
[ 7, 8, 8, 7, 7 ]
Explanation. 7 appears three times and 8 appears twice, 7 does not meet the even frequency requirement.
Follow-up: How would you optimize your solution for a very large input array?
1. The input array will contain at least one integer.\n2. All integers in the array will be positive.
- Views
- 3