Why I am getting output as 13 11 9 7 5 3 5 7 9 11 13 12 10 8 6 4 when my nums vector is [1,3,5,7,9,11,13]. I think it should be one of the combination of 1 3 5 7 9 11 13.
class Solution {
public:
int findLHS(vector<int>& nums) {
unordered_map<int,int> m;
for(auto e:nums){
m[e]++;
}
int maxLen=0;
for(auto it=m.begin();it!=m.end();it++)
{
int ele=it->first;
cout<<ele<<" ";
if(m[ele-1])
maxLen=max(maxLen,(m[ele]+m[ele-1]));
if(m[ele+1])
maxLen=max(maxLen,(m[ele]+m[ele+1]));
}
return maxLen;
}
};