From a74b44f15a796e367144ae63a5b5b97dcdd66c75 Mon Sep 17 00:00:00 2001 From: chayan das Date: Mon, 22 Sep 2025 16:26:00 +0530 Subject: [PATCH] Create 3005. Count Elements With Maximum Frequency 1 --- 3005. Count Elements With Maximum Frequency 1 | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 3005. Count Elements With Maximum Frequency 1 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; + } +};