Baap Solution || Must See After 22 Jan  || Best And Easiest Explanation ||
IntuitionCode
# Intuition
https://youtu.be/uAEBRPks97A

# Code
```cpp []
class Solution {
public:
    int maxSelectedElements(vector<int>& nums) { 
        sort(nums.begin(),nums.end());
        map<int,int>dp;
        for(auto num : nums){
            dp[num+1] = max(dp[num+1],1 + dp[num]);
            dp[num] = max(dp[num], 1 + dp[num-1]);
        }
        int ans = 0;
        for(auto x : dp){
            ans = max(ans,x.second);
        }
        return ans;
    }
};
```
['C++']