Time limit problem

I have just done a C programming on the problem Degree of Polynomial(Degree of Polynomial Practice Problem in 500 to 1000 difficulty problems - CodeChef).

Although I wrote the code correctly(as checked by AI), the status bar is showing 'time limit exceeded. Here is my code:

include <stdio.h>

int main(void) {
// your code goes here
int t,n,i,p,q;
int johny[1000];
scanf(“%d”,&t);
while(t–)
{ p=0,q=0;
scanf(“%d”,&n);
for(i=n;i>0;i++)
{
scanf(“%d”,&johny[i-1]);
}
for(i=0;i<n;i++)
{
if(johny[i]!=0)
{
q=n-i-1;
break;
}
}
printf(“%d\n”,q);
}
}

Please help me to find out how I can resolve this.

for(i=n;i>0;i++)
{
scanf(“%d”,&johny[i-1]);
} This part here,i should be i–

Your code gets stucked here:

for(i=n;i>0;i++)
{
    scanf(“%d”,&johny[i-1]);
}

Your variable “i” should be decreasing (i–), not increasing.

Thanks a lot…I really overlooked this.

1 Like

Thanks a lot.