DP
Solution-1: DP (Tabulation)\n### Idea\n+ The key here is to think in terms of what could be the longest CONSECUTIVE sequence possible ending at (any) particular
# Solution-1: DP (Tabulation)\n### Idea\n+ The key here is to think in terms of `what could be the longest CONSECUTIVE sequence possible ending at (any) particular number?`\n\n### Complexity\n+ **Time:** O(N)\n+ **Space:** O(N)\n\n### Code:\n```\nclass Solution \n{\npublic:\n    int maxSelectedElements(vector<int>& nums) \n    {\n        sort(nums.begin(), nums.end());\n        vector <int> dp(1000002,0);\n        \n        for ( const int& num : nums ) \n        {\n            dp[num+1] = 1 + dp[num];\n            dp[num] = max(dp[num], 1+dp[num-1]);\n        }\n\n        return *max_element(dp.begin(), dp.end());\n    }\n}\n```
['Dynamic Programming', 'C']