HELP IN MODEFREQ

but not getting tle

You declared vector with size 10. I think thats the problem.

no I have change it
#include <bits/stdc++.h>
using namespace std;

int main() {
long long t;
cin>>t;
while(t–)
{
long long n=0;
cin>>n;

    int c1=0,c2=0,a1=0,b1=0;
 int x;
    vector<int> a(11,0);
   for(int i=0;i<n;i++)
  {
  cin>>x;
  a[x]++;
   }


    int c=*max_element(a.begin(), a.end());
    for(int i=0;i<=n;i++)
    {
        if(a[i]==c)
       { c1++;
       a1=a[i];}
        else
        if(a[i]==c-1)
       { c2++;
       b1=a[i];}
    }
    if(a1>b1&&c1>c2)
    cout<<a1<<endl;
    else
    cout<<b1<<endl;
}

// your code goes here
return 0;

}
???

please share solution link

https://www.codechef.com/viewsolution/37287056
solution link

The below solution is accepted and it is easy to understand .
https://www.codechef.com/viewsolution/37279799

ok thanks for this
but can you tell me the problem in my solution

1
5
1 1 1 1 1
Try this

mine giving 5

its right, wait i’ll generate random test and we’ll figure it out

7
7 1 2 1 2 1 2 1
10 1 10 9 9 10 7 7 3 3 31
1 5
6 2 2 2 2 2 2
6 1 1 2 2 3 3
9 1 2 3 4 5 6 7 8 9
12 10 10 12 12 1 1 1 1 20 20 19 18

output

3
2
1
6
2
1
2

its fine here too

but for the first round output should be 1

7 => 1
1=> 4
2=> 3

1
5 1 1 1 1 2

try this

1 Like

7 is n, bruh

I told you because this method is used frequently and may be in some different question, chances are high that you may get tle. You can’t be lucky every time :sweat_smile:

1 2 1 2 try this

Can someone help me with my code as well. Where have I gone wrong? My guess is maybe in the for loop but I can’t figure it out.
https://www.codechef.com/viewsolution/37290671

bruh i think u missed braces in if else