Submission of Java code in codechef

Hi there,
I am having problem with submission of java code regarding its I/O format. My same logic is working fine with python or c++ but not in java, I am getting nzec, Wrong answer most of the time please go through my code and suggest me something, I tried try and catch method also.

//Here is the question : CodeChef: Practical coding for everyone

// My code
package leetcode;
import java.io.;
import java.util.
;
import java.lang.*;
class Tree {
public static void main(String[] args) throws java.lang.Exception {
// TODO Auto-generated method stub
BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(s.readLine());
while(n–>0)
{
int len=Integer.parseInt(s.readLine());
long arr[]=new long[len];
String [] S=s.readLine().split(" ");
for(int i=0;i<len;i++)
{
arr[i]=Long.parseLong(S[i]);
}
HashSet h=new HashSet();
for(long i:arr)
{
h.add(i);
}
if(h.contains(0))
System.out.println(h.size()-1);
else
System.out.println(h.size());
}
}

}

You might need to guard against nulls when you readLine() . It’s weird, but happened to me.

1 Like