Can anyone tell me why my answer is wrong? I tried running my program with custom input and it worked all the time. What’s the matter with my code?
#include <stdio.h>
int max (int *parr,int n){
int max=parr[0];
int maxidx;
int i;
for(i=0;i<n;i++)
{
if(parr[i]>max){
max=parr[i];
maxidx=i;}
}
return maxidx;
}
void rainbow(int *parr, int n)
{
int i;
if(n%2==0)
{
printf("No\n");
}else if(parr[max(parr,n)]-parr[max(parr,n)-1]>1)
{
printf("No\n");
}else
{
printf("Yes\n");
}
}
int main(void) {
int t;
int n,c;
int arr[100];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&c);
arr[i]=c;
}
rainbow(arr,n);
}
return 0;
}