Help me in solving CONSPERM problem

My issue

  1. I have initialized numbers to array
  2. I Calculater sum of every subArray
  3. I checked whether sum is Divisible by (n+1) or not
  4. If divisible printed -1 and if not I printed array

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc = new Scanner(System.in);
	    int t = sc.nextInt();
	    while(t-->0)
	    {
	        int n = sc.nextInt();
	        int a[] = new int[n];
	        boolean found = true;
	        for(int i=0;i<n;i++){
	            a[i] = i+1;
	        }
	        int sum = 0;
	        for(int i=0;i<n;i++){
                for(int j=i;j<n;j++){
                    sum = sum + a[j];
                }
                if(sum%(n+1) == 0){
                    found = false;
                }
            }
            if(found){
                for(int i=1;i<=n;i++){
                    System.out.print(i+" ");
                }
                System.out.println();
            }else{
                System.out.println("-1");
            }
            
	    }
	}
}

Problem Link: Construct Permutation Practice Coding Problem

you are only making a series of first n natural number which may give some substring that has sum divisible by(n+1) you print -1
but there may be any other permutation that can have sum not divisble by (n+1)
Ex:- n=5
ans can be
1 4 3 2 5
but you will be printing -1

Ok Thanks Very much. It helped me a lot

No Problem