-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProblem-1.java
44 lines (34 loc) · 845 Bytes
/
Problem-1.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
/**
* @author AkashGoyal
*/
/**
--------------------- Problem----------->> find a pair with a given difference
Problem Link :- https://practice.geeksforgeeks.org/problems/find-pair-given-difference1559/1
Reference Link:- https://www.youtube.com/watch?v=5IUyc7cPD9E
*/
class Solution
{
public boolean findPair(int arr[], int size, int n)
{
//code here.
Arrays.sort(arr);
// 2 3 5 5 20 80
int left=0;
int right=1;
while(left<size && right<size)
{
if(arr[right]-arr[left]>n)
{
left++;
}
else if(arr[right]-arr[left]<n){
right++;
}
else
{
return true;
}
}
return false;
}
}