Count Elements With Maximum Frequency - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,3,2,3,3]
›
Output:
3
💡 Note:
Element 3 appears 3 times (maximum frequency). Elements 1 and 2 appear 1 time each. Total frequency of elements with maximum frequency = 3.
Example 2 — Multiple Elements with Same Max Frequency
$
Input:
nums = [1,1,2,2,3]
›
Output:
4
💡 Note:
Elements 1 and 2 both appear 2 times (maximum frequency). Element 3 appears 1 time. Total frequency of elements with maximum frequency = 2 + 2 = 4.
Example 3 — All Elements Same Frequency
$
Input:
nums = [1,2,3]
›
Output:
3
💡 Note:
All elements appear 1 time (maximum frequency). Total frequency = 1 + 1 + 1 = 3.
Constraints
- 1 ≤ nums.length ≤ 100
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code