Why am I getting NZEC?
Problem: CodeChef: Practical coding for everyone
public static void main (String[]args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner (System.in);
int n = in.nextInt ();
int count=0;
int[] a=new int[n];
for (int i = 0; i < n; i++)
{
a[i]=in.nextInt();
}
Arrays.sort(a);
for (int i = 0; i < n; i++)
{
int l=0;
int r=1;
while(l<=i && r<=n-i)
{
if ((a[i]-a[i-l])==(a[i+r]-a[i]))
{
count++;
break;
}
else if (i==0 && r<n-i)
{
r++;
continue;
}
else if (i==n-1 && l<i)
{
l++;;
continue;
}
else if ((a[i]-a[i-l])<(a[i+r]-a[i]) && l<i)
{
l++;
continue;
}
else if ((a[i]-a[i-l])<(a[i+r]-a[i]) && r<n-i)
{
r++;
continue;
}
break;
}
}
System.out.println(count);
}