Sum of highest and lowest frequency

Beginner Problems Basic Hashing Easy
  • This programming problem is conceptually related to data analysis and statistics, often used in the software industry for user behavior analysis, trend identification, and recommendation systems
  • The identification of the most and least frequent values (modal and anti-modal values) is commonly used in sectors like e-commerce and social media to understand user preferences and trends, such as the highest and lowest selling products, or the most and least liked posts

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