Nzec error while submitting ?

Nzec error while submitting ? While it runs well in my pc ?

// My code is
import java.lang.*;
import java.util.Scanner;
class Temple
public static boolean check()
Scanner s = new Scanner(;
int i=0,n=0;
int arr[]= new int[100];
return false;
int h=n/2;
return false;
return true;

// And its main. public static void main(String[] args)
Scanner sc = new Scanner(;
int s=0;
int i=0;

NZEC error is basically NON ZERO EXIT CODE.

In java, the prime reason for this is IndexOutOfBounds Exception, whether it may be string index or array…

Although NZEEC is given by any Exception thrown, IndexOutOfBounds Exception is prime reason for probably 95% NZEC submissions…

Hope this clarfies any doubt…

Please UPVOTE and Accept the answer if you find this helpful…


You are initializing the array in a wrong way.

You should declare array as

int N= in.nextInt();

int arr[] = new int[N];

I hope this resolves the problem…

Please UPVOTE…

The problem TEMPLELA has a simpler solution.

When N is even, answer is invalid as there’s no possible heights satisfying all requirements…

When N is odd, observe ans for Odd values of N

N = 3: 1 2 1

N = 5: 1 2 3 2 1

N = 7: 1 2 3 4 3 2 1

A single loop in java

int N = in.nextInt();

int[] height = new int[N];

boolean ans = true;

for(int i = 0; i<N; i++)height[i] = in.nextInt();

for(int i = 0; i< N; i++){

   if(i < (N-1)/2){

           if(height[i] != i+1)ans = false;

   }else if(i == (N-1)/2){

           if(height[i] != (N+1)/2)ans = false;


           if(height[i] != N - i)ans = false;



if(ans && (N%2 != 0))System.out.println(“yes”);

else System.out.println(“no”);

PS: I know i shouldn’t post the whole solution, but it’s your first one, so cheers…

Please UPVOTE if you find this helpful…