Codechef Chef and Rainbow Array Problem

      No Comments on Codechef Chef and Rainbow Array Problem

Codechef Chef and Rainbow Array Problem Code: RAINBOWA

Codechef Chef and Rainbow Array Problem

Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays.

An array is Rainbow if it has the following structure:

  • First a1 elements equal 1.
  • Next a2 elements equal 2.
  • Next a3 elements equal 3.
  • Next a4 elements equal 4.
  • Next a5 elements equal 5.
  • Next a6 elements equal 6.
  • Next a7 elements equal 7.
  • Next a6 elements equal 6.
  • Next a5 elements equal 5.
  • Next a4 elements equal 4.
  • Next a3 elements equal 3.
  • Next a2 elements equal 2.
  • Next a1 elements equal 1.

ai can be any non-zero positive integer.
There are no other elements in array.

Help Chef in finding out if the given array is a Rainbow Array or not.

Input

The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains an integer N, denoting the number of elements in the given array.
The second line contains N space-separated integers A1, A2, …, AN denoting the elements of array.

Output

For each test case, output a line containing “yes” or “no” (without quotes) corresponding to the case if the array is rainbow array or not.

Constraints

  • 1 ≤ T ≤ 100
  • 7 ≤ N ≤ 100
  • 1 ≤ Ai ≤ 10

Solution

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int *a=(int *)malloc((n+1) * sizeof(int));
		int i,j;
		a[0]=0;
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
			
					for(i=1,j=n;i<j;i++,j--)
			if(a[i]!=a[j] || a[i+1]-a[i]>1 || a[i+1]-a[i]<0 || a[i]<1 || a[i]>7)
				break;
		if(i < j || a[i]!=7)
			printf("no\n");
		else
			printf("yes\n");
	}
}

Codechef Chef and Rainbow Array Problem

Summary
Codechef Chef and Rainbow Array Problem
Article Name
Codechef Chef and Rainbow Array Problem
Description
Codechef Chef and Rainbow Array Problem -Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure...
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *