Count Elements With Maximum Frequency

You are given an array nums consisting of positive integers.

Return the total frequencies of elements in nums such that those elements all have the maximum frequency.

The frequency of an element is the number of occurrences of that element in the array.

Example 1
Inputnums = [1,2,2,3,1,4]
Output4
The elements 1 and 2 have a frequency of 2, which is the maximum frequency in the array, so the total number of occurrences among them is 4.
Example 2
Inputnums = [1,2,3,4,5]
Output5
All elements have a frequency of 1, which is the maximum, so the total number of occurrences among them is 5.

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 8 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate