Better
It now fails on the following test input:
1
13
2 2 3 4 5 6 7 6 5 4 3 2 2
Better
It now fails on the following test input:
1
13
2 2 3 4 5 6 7 6 5 4 3 2 2
got it
Thanks
My code: Rainbowa
I’m not able to find the test case that is getting failed. Someone please help me with this code.
Will the list contain elements valued only upto 7 or can it take up values like 8 9 also? Like is
1 2 3 4 4 5 6 7 7 8 7 7 6 5 4 4 3 2 1 valid??
1 2 3 4 4 5 6 7 7 8 7 7 6 5 4 4 3 2 1 is not valid. The array can contain elements only upto 7
Hello everyone,
I am unable to find out why my code gives a WA. Can someone please help me.
https://www.codechef.com/viewsolution/36204637
Here is a solution using the regex. We have to ensure following checks:
First 3 cases can be checked using regex:
^[1]+[2]+[3]+[4]+[5]+[6]+[7]+[6]+[5]+[4]+[3]+[2]+[1]+$
Now we need to check if the numbers appear like a palindrome.
Below is my code to check RAINBOW array using regex:
import java.io.IOException;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void isRainbow(int[] a, int N){
/*convert given integer array into string and then match with the regex;*/
String s1 = Arrays.toString(a).replaceAll("\\[","").replaceAll("\\]","").replaceAll(",","").replaceAll(" ","");
String regex = "^[1]+[2]+[3]+[4]+[5]+[6]+[7]+[6]+[5]+[4]+[3]+[2]+[1]+$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s1);
if(!matcher.matches()) {
System.out.println("no");
return;
}
/* Now check for the palindromic nature of the series */
int l = 0;
int r = N - 1;
while(l <= r){
if(a[l] != a[r]){
System.out.println("no");
return;
}
l++;
r--;
}
/* If the series passes all the checks then it is a rainbow array */
System.out.println("yes");
return;
}
public static void main (String[] args) throws java.lang.Exception{
Scanner sc = new Scanner(System.in);
int t = 0;
if(sc.hasNextInt())
t = sc.nextInt();
while(t-- > 0){
int N = sc.nextInt();
int[] a = new int[N];
for(int i = 0; i < N; i++){
if(sc.hasNextInt())
a[i] = sc.nextInt();
}
isRainbow(a, N);
}
}
}
Thanks!!
Thank you… i was really very confused.
can anyone please figure out what is the wrong with this code sample input is showing positive result
t=int(input())
for i in range(t):
flag=True
array=[]
n=int(input())
array=list(map(int,input().split()))
m=0;
g=n-1-m
c=array[m]
while m<=g and array[0]==1 and array[-1]==1:
if array[m]==array[g] and (array[m]==array[m-1] or array[m]==array[m-1]+1):
if m==g and array[m]==7:
break
m=m+1
g=n-1-m
else:
flag=False
break;
if flag :
if array[m]==7:
print('yes')
else:
print('no')
Yes the o/p is wrong it should come ‘no’ but it is coming ‘yes’.i got it why my algo is wrong Thank u very much @ssjgz
Gives no output for this
1
11
2 3 4 5 6 7 6 5 4 3 2
Yes because the first and last elements must be 1
Yeah! It doesnt even print “no”. That’s what I meant
Rememer to use ‘yes’ or ‘no’ instead of ‘Yes’ or ‘No’
What’s wrong in this solution https://www.codechef.com/viewsolution/41956567. It works fine in my code blocks IDE, but here it shows WA.