Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f2889e

Browse files
Create 08-03-2024.cpp
1 parent 907bd00 commit 8f2889e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎2024/03 - March/08-03-2024.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Author : Saransh Bangar
3+
Date : 08/03/2024
4+
Problem : Count Elements With Maximum Frequency
5+
Difficulty : Easy
6+
Problem Link : https://leetcode.com/problems/count-elements-with-maximum-frequency/description/
7+
Video Solution : NA
8+
*/
9+
10+
11+
class Solution {
12+
public:
13+
int maxFrequencyElements(vector<int>& nums)
14+
{
15+
vector<int> a(101, 0);
16+
17+
int maxFreq = INT_MIN;
18+
for(int i=0; i<nums.size(); i++) {
19+
a[nums[i]] += 1;
20+
maxFreq = max(maxFreq, a[nums[i]]);
21+
}
22+
23+
int count = 0;
24+
for(int i=0; i<nums.size(); i++)
25+
if(a[nums[i]] == maxFreq)
26+
count++;
27+
28+
return count;
29+
}
30+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /