My issue
Can anyone pls help me in resolving this issue for Time Limit exceeded in Equal Elements problem
My code
#include <stdio.h>
int main(void) {
// your code goes here
int t,N,count,grt,eql,temp;
scanf("%d",&t);
while(t--)
{
count = 0;
temp = 0;
eql = 0;
scanf("%d",&N);
int a[N],b[N];
for(int i=0;i <N; i++)
{
scanf("%d",&a[i]);
}
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++)
{
if(a[i]==a[j])
{
count = count + 1;
}
}
b[i] = count;
count = 0;
}
// all not equal
for(int i=0; i<N; i++)
{
if(b[i] == 1)
{
temp = temp + 1;
}
}
// all equal
for(int j=0; j<N; j++)
{
if(b[j] == N)
{
eql = eql + 1;
}
}
// some equal
for(int k=0; k<N; k++)
{
if(b[0] < b[k])
{
b[0] = b[k];
}
}
grt = b[0];
if(temp == N)
{
printf("%d \n",N-1);
}
else if(eql == N)
{
printf("0 \n");
}
else
{
printf("%d \n", N-grt);
}
}
return 0;
}
Learning course: Arrays, Strings & Sorting
Problem Link: CodeChef: Practical coding for everyone