why my RAINBOWA solution giving Wrong answer ????

import java.util.Scanner;

/**
*

  • @author HP
    */
    class Main {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      Scanner sc =new Scanner(System.in);
      int T,N;
      int[][] a;
      while(true){
      //System.out.println(“Enter the No of Test Cases:”);

      T =sc.nextInt();
       if(T>=1&&T<=100){
          a = new int[T][];
           break;
       }
      

      }
      for(int i=0;i<T;i++){
      while(true){
      // System.out.println(“Enter the no of elements in the given array”);
      N=sc.nextInt();
      if(N>=7&&N<=100){
      break;
      }
      }
      a[i]=new int[N];
      // System.out.println(“Enter the array”);
      for(int j=0;j<N;j++){
      while(true){
      // System.out.println(“Enter the no of elements in the given array”);
      a[i][j]=sc.nextInt();
      if(a[i][j]>=1&&a[i][j]<=10){
      break;
      }
      }

               //if(a[i][j]<1||a[i][j]>10)
                  // j--;
       }
      

      }
      int j,k;
      int count=1;
      int flag=0;
      for(int i=0;i<T;i++){
      j=0;
      k=a[i].length-1;

      count=1;

       while(j<=k){
           if(j!=0){
               if(a[i][j]!=a[i][j-1])
                   count++;
           }
           if((a[i][j]==a[i][k])&&(count==a[i][j])){
               
               j++;
               k--;
             
           }
           else //if ((a[i][j]==a[i][j+1]+1)||(a[i][j]==a[i][j+1]))
           {
               break;
               
           }
           
               
        ///   else{
           //    System.out.println("no");
             //  break;
           //}
       }
       if(j>k){
           System.out.println("yes");
       }
       else{
           //System.out.println("j="+j+": k="+k);
           System.out.println("no");
       }
      

      }

    }

    }

You shouldn’t be printing those arbitrary statements like “Enter the number of test cases”. It’s a machine checking your answer so just print either “yes” or “no”

Where are you checking that elements [1,7] are compulsarily there?

You are failing here-

Input
1
13
1 1 1 1 1 1 1 1 1 1 1 1 1
Your output
yes
Expected Output
no
1 Like

He has commented it.Even I was in your shoes at first :stuck_out_tongue:

Ahh wasn’t expecting that

please check my solution, its giving wa.

#include <iostream>
using namespace std;

int main() {
   int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int i,j;
        for(int i=0; i<n; i++){
            cin>>a[i];
        }
        string ans="no";
        if(a[0]==1 && a[n-1]==1){
            i=1;
            j=n-2;
            while(i<j){
                if(a[i]==a[j] && (a[i]==a[i-1]+1 || a[i]==a[i-1]) ){
                    i++;
                    j--;
                }
                else break;
            }
            if(i==n/2 && a[i]==7) ans="yes";  
            
        }

        cout<<ans<<endl;
    }
	// your code goes here
	return 0;
}

Consider the test input:

1
7
1 2 3 7 3 2 1

thanks a ton friend, you saved a hell lot of my time in debugging. :hugs:

1 Like