Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
278 B
1
Indexable
Never
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;
    }
};
Leave a Comment