749. Sum of Highest and Lowest Frequency
Given an array of n integers, find the sum of the frequencies of the highest occurring number and lowest occurring number.
Example 1:
Input: arr = [1, 2, 2, 3, 3, 3]
Output: 4
Explanation: The highest frequency is 3 (element 3), and the lowest frequency is 1 (element 1). Their sum is 3 + 1 = 4.
Example 2:
Input: arr = [4, 4, 5, 5, 6]
Output: 3
Explanation: The highest frequency is 2 (elements 4 and 5), and the lowest frequency is 1 (element 6). Their sum is 2 + 1 = 3.
Now Your Turn!
Pick the correct output for the given inputInput: arr = [10, 9, 7, 7, 8, 8, 8]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 105
- 1 <= arr[i] <= 104