I want to count the number of duplicate elements in an array. My code works fine in my Compiler but when I try to submit my code it shows TLE(Time Limit Exceeded) Error. My code is here:
public static void main(String[] args) throws IOException {
Scanner s= new Scanner(System.in);
long count=0;
long n=s.nextLong();
for(int i=0; i<n; i++) {
int g=s.nextInt();
int []arr=new int [g];
for(int j=0; j<g; j++) {
arr[j]=s.nextInt();
}
for(int j=0; j<g; j++) {
for(int k=j+1; k<g; k++) {
if(arr[j]==arr[k]) {
count++;
}
}
}
System.out.println(count);
count=0;
}
}
}