-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.java
67 lines (51 loc) · 1.58 KB
/
3.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine());
while (tc-- > 0) {
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
String[] inputLine = br.readLine().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(inputLine[i]);
}
boolean ans = new Solution().checkTriplet(arr, n);
System.out.println(ans ? "Yes" : "No");
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution {
boolean checkTriplet(int[] arr, int n) {
int max = Integer.MIN_VALUE;
for(int i=0;i<n;i++){
arr[i] = arr[i] * arr[i];
}
//find max value;
for(int i=0;i<n;i++){
max = Math.max(max,arr[i]);
}
Set<Integer> set = new HashSet<>();
for(int i=0;i<n;i++){
set.add(arr[i]);
}
for(int i=max;i>0;i--){
if(set.contains(i)){
for(int j=0;j<n;j++){
if(arr[j] == max){
continue;
}
if(set.contains(Math.abs(i-arr[j]))){
return true;
}
}
}
}
return false;
}
}