Skip to content

Commit 0ce072a

Browse files
authored
Create main.cpp
1 parent 8cfbcb0 commit 0ce072a

File tree

1 file changed

+17
-0
lines changed
  • 20 - Hashmap Data Structure Problems/02 - Count Elements With Maximum Frequency

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)