forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffK.java
More file actions
36 lines (30 loc) · 635 Bytes
/
DiffK.java
File metadata and controls
36 lines (30 loc) · 635 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
33
34
35
36
package TwoPointers;
import java.util.ArrayList;
/**
* Author - archit.s
* Date - 16/10/18
* Time - 11:07 AM
*/
public class DiffK {
public int diffPossible(ArrayList<Integer> A, int B) {
int i = 0;
int j = 1;
while(i!=A.size() && j!= A.size()){
if(i == j){
j++;
continue;
}
int diff = A.get(j) - A.get(i);
if(diff == B){
return 1;
}
else if(diff > B){
i++;
}
else{
j++;
}
}
return 0;
}
}