//时间复杂度有要求
class Solution {
public int longestSubsequence(int[] arr, int difference) {
int n=arr.length;
int ans=0;
HashMap<Integer,Integer> map=new HashMap<>();
for(int i=0;i<n;i++){
if(map.containsKey(arr[i]-difference)){
map.put(arr[i],map.get(arr[i]-difference)+1);
ans=Math.max(ans,map.get(arr[i]));
}
if(!map.containsKey(arr[i])) map.put(arr[i],0);
}
return ans+1;
}
}