class Solution {
public int longestSubsequence(int[] arr, int difference) {
if (arr.length == 0) {
return 0;
}
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
int tmp = arr[i] - difference;
if (!map.containsKey(tmp)) {
map.put(tmp, 0);
}
map.put(arr[i], map.get(tmp) + 1);
}
int res = 1;
for (Integer i : map.keySet()) {
res = Math.max(res, map.get(i));
}
return res;
}
}