Chef and Rainbow Array in C

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;
}

You should be printing all lowercase characters “yes” instead of “Yes”
and “no” instead of “NO”

Hope this helps!!

1 Like

Thank you for your help but it’s not working… :frowning:

1

11

1 2 4 5 6 7 6 5 4 2 1

Your output

yes

Expected output

No

So, make sure the array only increase by 1 or 0 or decrease by -1 and 0

in the above case 1 2 4 5 6 7 6 5 4 2 1
although it looks rainbow array but look at the difference between the second and third element is greater than 1 so it’s not a rainbow array

and also one more thing the rainbow array should go till 7

for ex 1 2 3 4 5 6 7 7 6 5 4 3 2 1(this is rainbow array) so you can’t say if the n is even it’s not an rainbow array

while 1 2 3 2 1(this is not an rainbow array)

//