My issue
Why wouldn’t my logic work?
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
HashSet<Integer> hs = new HashSet<>();
int arr[] = new int[n];
int flag=0;
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
for(int j=0;j<i;j++){
int a=arr[i]-arr[j];
if(hs.contains(a)){
flag=1;
break;
}else{
hs.add(a);
}
}
}
if(flag==1){
System.out.println("NO");
}else{
System.out.println("YES");
}
}
}
}
Problem Link: AP Free Sequences Practice Coding Problem - CodeChef