a simple naive approach.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \ncheck each element if w
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ncheck each element if we increase by one then the number of sequence or doesn\'t increase it.\nfind the max.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn).\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxSelectedElements(vector<int>& nums) {\n        unordered_map<int,int>dp;\n        sort(nums.begin(),nums.end());\n        int ans=0;\n        for(int num:nums){\n            dp[num+1]=dp[num]+1;\n            dp[num]=dp[num-1]+1;\n            ans=max({ans,dp[num+1],dp[num]});\n        }\n    return ans;\n    }\n};\n```
['Dynamic Programming', 'C++']