-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpairwithdifferencek.java
More file actions
32 lines (29 loc) · 869 Bytes
/
pairwithdifferencek.java
File metadata and controls
32 lines (29 loc) · 869 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
29
30
31
32
import java.io.*;
import java.util.*;
public class Main {
static boolean diff(int n,long arr[],int k){
Arrays.sort(arr);
int i=0;
int j=0;
while( i<n && j<n){
if(arr[j]-arr[i]==k && i!=j) return true;
else if(arr[j]-arr[i]<k){j++; continue;}
i++;
}
return false;
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t--!=0){
int n=s.nextInt();
int k=s.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i]=s.nextLong();
}
System.out.println(diff(n,arr,k));
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Main. */
}
}