We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8cfbcb0 commit 0ce072aCopy full SHA for 0ce072a
20 - Hashmap Data Structure Problems/02 - Count Elements With Maximum Frequency/main.cpp
@@ -0,0 +1,17 @@
1
+class Solution {
2
+public:
3
+ int maxFrequencyElements(vector<int>& nums) {
4
+ unordered_map<int, int> freqMap;
5
+
6
+ for(auto i : nums) freqMap[i]++;
7
8
+ int maxFreq = 0;
9
10
+ for(auto pair : freqMap) maxFreq = max(maxFreq, pair.second);
11
12
+ int totalCount = 0;
13
+ for (auto pair : freqMap) if (pair.second == maxFreq) totalCount += pair.second;
14
15
+ return totalCount;
16
+ }
17
+};
0 commit comments