Can someone Help me with MY code ?.. I think I am missing a corner case...

Revision en3, by JOSBEAK, 2021-04-02 13:19:32

Question Link:- https://mirror.codeforces.com/contest/1506/problem/D

My Solution:-

int main() {

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;

cin>>t;

while(t--) {

int n,x=0,d=1;

cin>>n;

int a[n];

int count=1;

for(int i=0;i<n;i++)

{

cin>>a[i];

}

sort(a,a+n);

for(int i=0;i<n-1;i++)

{

if(a[i]==a[i+1])

 {

     count++;

 }

 else

 {
     d++;

if(x<count)

{

     x=count;

 }


 count=0;

 }

 }

 if(x==n/d&&n%2==0)

 {

     cout<<"0"<<endl;

 }

 else

cout<<abs((2*x)-n)<<endl;

}

return 0;

}

Getting wrong answer on 2nd test case .

Tags #help, corner case, code review

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English JOSBEAK 2021-04-02 22:58:34 7
en5 English JOSBEAK 2021-04-02 13:42:04 1 Tiny change: 'Solution:-https://co' -> 'Solution:- https://co'
en4 English JOSBEAK 2021-04-02 13:41:44 663
en3 English JOSBEAK 2021-04-02 13:19:32 83
en2 English JOSBEAK 2021-04-02 13:17:45 2 Tiny change: 'lution:-\nint main' -> 'lution:-\n\nint main'
en1 English JOSBEAK 2021-04-02 13:17:17 774 Initial revision (published)