Skip to content

Commit 2538604

Browse files
committed
Runtime: 157 ms (Top 72.81%) | Memory: 44.7 MB (Top 76.75%)
1 parent 44b545b commit 2538604

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
// Runtime: 157 ms (Top 72.81%) | Memory: 44.7 MB (Top 76.75%)
2+
13
class Solution {
24
public:
35
int maxEqualFreq(vector<int>& nums) {
46
int n=nums.size();
5-
unordered_map<int,int> mp1,mp2; //one to store the frequency of each number , and one which will store the frequency of the frequency
7+
unordered_map<int,int> mp1,mp2; //one to store the frequency of each number , and one which will store the frequency of the frequency
68
int ans=0;
79
for(int i=0;i<n;i++)
810
{
911
int c=nums[i];
1012
mp1[c]++;
1113
mp2[mp1[c]]++;
12-
if(i!=n-1 && mp2[mp1[c]]*mp1[c]==i+1)
13-
//when curernt length is equal to the total same frequency of numbers then we need one more
14-
//number which may be anything so doesn't matter .
15-
//so we just traverse till n-2 and that's it.
16-
17-
14+
if(i!=n-1 && mp2[mp1[c]]*mp1[c]==i+1)
15+
//when curernt length is equal to the total same frequency of numbers then we need one more
16+
//number which may be anything so doesn't matter .
17+
//so we just traverse till n-2 and that's it.
18+
1819
ans=i+2;
1920
if(mp2[mp1[c]]*mp1[c]==i)
20-
//when current length is equal to the total same frequency of numbers plus one extra no.
21-
//( so here taken ==i (i+1-1)) which can be 1. same as any number present 2. different number ..
22-
//but doesn't matter and our condition just satisfies ... so just take the current length .
23-
24-
21+
//when current length is equal to the total same frequency of numbers plus one extra no.
22+
//( so here taken ==i (i+1-1)) which can be 1. same as any number present 2. different number ..
23+
//but doesn't matter and our condition just satisfies ... so just take the current length .
24+
2525
ans=i+1;
2626
}
2727
return ans;
2828
}
29-
};
29+
};

0 commit comments

Comments
 (0)