Untitled
Anonymous
Plain Text
03/07/2024 1:49 PM
278 B
17
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;
}
};Editor is loading...
Leave a Comment