×

# Chef and Rainbow Array in C

 0 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 int max (int *parr,int n){ int max=parr[0]; int maxidx; int i; for(i=0;imax){ 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

 1 You should be printing all lowercase characters "yes" instead of "Yes" and "no" instead of "NO" Hope this helps!! answered 04 Sep '17, 20:46 2★kunnu120 518●9 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) kunnu1202★ 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) kunnu1202★ 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) kunnu1202★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,470
×836
×228
×148
×100
×28

question asked: 04 Sep '17, 20:41

question was seen: 470 times

last updated: 05 Sep '17, 08:32