No DP -- Just Sorting + Hash map based easy C++ Solution
Complexity\n- Time complexity: O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:  O(n)\n Add your space complexity here, e.g. O(n) \n\
# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:  O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxSelectedElements(vector<int>& nums) {\n        sort(nums.begin() , nums.end());\n        unordered_map<int,int> mp;\n        for(auto x : nums)cout<<x<<" ";\n        cout<<endl;\n        auto n = nums.size();\n        mp[nums[n-1]]=1;\n        mp[nums[n-1]+1]=1;\n        for(int i = n - 2 ; i>= 0 ;i--){\n           int number = nums[i];\n           int number2 = nums[i]+1;\n           if(mp.find(number+1)!=mp.end())mp[number] = mp[number+1]+1;\n           else mp[number] = 1;\n           if(mp.find(number2+1)!=mp.end())mp[number2] = mp[number2+1]+1;\n           else mp[number2] = 1;\n        }\n        int result = 0;\n        for(auto x : mp)result = max(result , x.second);\n        return result;\n    }\n};\n```
['C++']