diff --git a/3005. Count Elements With Maximum Frequency 1 b/3005. Count Elements With Maximum Frequency 1 new file mode 100644 index 0000000..f8bf0a8 --- /dev/null +++ b/3005. Count Elements With Maximum Frequency 1 @@ -0,0 +1,22 @@ +#include +#include +#include +using namespace std; + +class Solution { +public: + int maxFrequencyElements(vector& nums) { + unordered_map freq; + // Count frequency of each number + for (int x : nums) freq[x]++; + + // Find maximum frequency + int maxFreq = 0; + for (auto &p : freq) maxFreq = max(maxFreq, p.second); + + // Sum frequencies of elements that have frequency == maxFreq + int result = 0; + for (auto &p : freq) if (p.second == maxFreq) result += p.second; + return result; + } +};