Simplest solution || C++ || LIS
Intuition\n Describe your first thoughts on how to solve this problem. \nSimilar to LIS\n\n# Approach\n Describe your approach to solving the problem. \n\n# Com
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimilar to LIS\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```\nclass Solution {\npublic:\n    int maxSelectedElements(vector<int>& nums) {\n        sort(nums.begin() , nums.end());\n        map<int ,int> m;\n        int ans = 0;\n        for(auto i : nums){\n            int end1 , end2;\n            if(m.find(i-1) != m.end()){\n                end1 = m[i-1]+1;\n            }else{\n                end1 = 1;\n            }\n            if(m.find(i) != m.end()){\n                end2 = m[i]+1;\n            }else{\n                end2 = 1;\n            }\n            ans = max({ans,end1,end2});\n            m[i] = end1;\n            m[i+1] = end2;\n        }\n        return ans;\n    }\n};\n```
['C++']