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
Understanding the Visualization
1
Input Array
Array of positive integers with varying frequencies
2
Count Frequencies
Build frequency map and find maximum frequency
3
Sum Maximum Frequencies
Add up frequencies of elements with maximum count
Key Takeaway
🎯 Key Insight: Track maximum frequency dynamically while building frequency map for optimal O(n) solution
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code