You are not logged in. Please login at www.codechef.com to post your questions!

×

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

asked 04 Sep '17, 20:41

delock's gravatar image

0★delock
1
accept rate: 0%


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

Hope this helps!!

link

answered 04 Sep '17, 20:46

kunnu120's gravatar image

1★kunnu120
5079
accept rate: 5%

Thank you for your help but it's not working... :(

(05 Sep '17, 08:12) delock0★

1

11

1 2 4 5 6 7 6 5 4 2 1

Your output

yes

Expected output

No

(05 Sep '17, 08:18) kunnu1201★

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

(05 Sep '17, 08:21) kunnu1201★

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)

(05 Sep '17, 08:32) kunnu1201★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,402
×790
×170
×144
×78
×25

question asked: 04 Sep '17, 20:41

question was seen: 367 times

last updated: 05 Sep '17, 08:32