-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAP_Free_Sequences.java
More file actions
28 lines (27 loc) · 926 Bytes
/
Copy pathAP_Free_Sequences.java
File metadata and controls
28 lines (27 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public static void main(String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader();
int t, n;
t = sc.nextInt();
while (t-- > 0) {
n = sc.nextInt();
boolean ans = true; // Reset ans to true for each test case
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
for(int k=j+1;k<n;k++){
if(a[j]-a[i]==a[k]-a[j]){
ans=false;
break;
}
}
}
}
System.out.println(ans?"YES":"NO");
}
}
// we need to use brute force to solve this problem, i tried different approach of using map as well but it was failing
// in non consecutive triplets for AP series therefore we have to use O(n^3) approach