> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/hashmap-and-hashset-and-sliding-window/untitled.md).

# Diffk II

Given an array `A` of integers and another non negative integer `k`, find if there exists 2 indices `i` and `j` such that `A[i] - A[j] = k, i != j`.

**Example :**

Input :

```
A : [1 5 3]
k : 2
```

Output :

```
1
```

as `3 - 1 = 2`

* Return `0 / 1` for this problem.

```java
public class Solution {
    // DO NOT MODIFY THE LIST. IT IS READ ONLY
    public int diffPossible(final List<Integer> A, int B) {
        Set<Integer> visited = new HashSet<Integer>();
        for (Integer number : A) {
            if (visited.contains(number + B) || visited.contains(number - B))
                return 1;
            visited.add(number);
        }
        return 0;
    }
}
```
