Count Elements With Maximum Frequency

You are given an array nums 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.

30:00

Count Elements With Maximum Frequency
easy
Free written solution
Topics
Companies

You are given an array nums 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:
Input: {"nums":[1,2,2,3,1,4]}
Output: 4
Constraints:
  • 1≤nums.length≤1001 \leq \text{nums.length} \leq 100

  • 1≤nums[i]≤1001 \leq \text{nums}[i] \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,2,2,3,1,4]}

Drop each number onto its own column. best is the tallest column so far, total counts the elements in all columns that tall.

nums

1
2
2
3
1
4

count per value

no columns yet

best

0

total

0

0 column(s) at the bar

Variables
VariableValue
best0
total0
DepthFunction Call
Stack empty
0/13