best cpp solution 100% passed test cases
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\nunordered_map<int,int> um;\n    int maxSelectedElements(vector<int>& nums) {\n        int n=nums.size();\n        sort(nums.begin(),nums.end());\n        int maxi=INT_MIN;\n        for(int i=0;i<n;i++){\n            int el=nums[i];\n            um[el+1]=um[el]+1;\n            um[el]=um[el-1]+1;\n            maxi=max(maxi,max(um[el+1],um[el]));\n        }\n        return maxi;\n        \n    }\n};\n```
['C++']