Sum of highest and lowest frequency

Beginner Problems Basic Hashing Easy

Given an array of n integers, find the sum of the frequencies of the highest occurring number and lowest occurring number.

Examples:

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.

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.

Input: arr = [10, 9, 7, 7, 8, 8, 8]

Constraints

  • 1 <= n <= 104
  • 1 <= arr[i] <= 104

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree