Untitled
unknown
plain_text
2 years ago
278 B
10
Indexable
class Solution {
public:
int longestSubsequence(vector<int>& arr, int dif) {
int res=1;
unordered_map<int,int>mp; //initial value 0
for(int &i:arr){
mp[i]=1+mp[i-dif];
res=max(res,mp[i]);
}
return res;
}
};Editor is loading...
Leave a Comment