CLCO04(hopscotch)

what is wrong in my code?
Actually i am getting the o/p in my compiler but while submitting to the code chef i am getting wrong answer.
#include<stdio.h>
int main() {
int n,m;
int t,i,j,temp;

scanf("%d",&t);
while(t--)   {
	int flag=0;
	scanf("%d%d",&n,&m);
	int a[m];
	for(i=1;i<=m;i++)   {
		scanf("%d",&a[i]);
	}
	for(i=1;i<m;i++)  
	for(j=1+i;j<=m;j++)   
	if(a[i]>a[j])   {
	  temp=a[i];
	  a[i]=a[j];
	  a[j]=temp;	
	}
//	for(i=1;i<=m;i++)
//	printf("\t%d",a[i]);
	  for(i=1;i<m-1;i++)  
	  if(a[i]==(a[i+1]-1)&&a[i]==(a[i+2]-2))	{
	  flag=1;
	  break;
         }
	if(flag==1)
	printf("NO\n");
	else
	printf("YES\n");

}
return 0;
}

I think you should take care of the case when the array contains 1 or a number equals to n. in that case the jump couldn’t be completed.

1 Like