Simple scan. Code with detailed comments
We are looking for a sequence of increasing numbers. We can make this easier by sorting the array first since the original ordering doesn\'t matter.\n\nThen we 
We are looking for a sequence of increasing numbers. We can make this easier by sorting the array first since the original ordering doesn\'t matter.\n\nThen we can greedily increase the sequence seen so far and reset when we can\'t. (Details of the reset are in the comments.)\n\nThe backtracking that is done during a reset will never go back over the same number more than once (since gaps of 2 will break the backtracking iteration and are also where we start from), so it keeps the time complexity of the greedy iteration as $$O(n)$$.\n\n# Complexity\n- Time complexity: $$O(n*log(n))$$\n\n- Space complexity:  $$O(1)$$\n\n# Code\n```\nclass Solution\n{\npublic:\n\tint maxSelectedElements(vector<int>& nums)\n\t{\n\t\t// order the numbers\n\t\tsort(nums.begin(), nums.end());\n\n\t\tint maxSize = 1;\n\t\tint curSize = 1;\n\t\tint lookingFor = -100;\n\t\tfor (int i = 0; i < nums.size(); ++i)\n\t\t{\n\t\t\t// The next number is the one we are looking for,\n            // or we can modify it by increasing its value by 1\n\t\t\tif (nums[i] == lookingFor || nums[i] + 1 == lookingFor)\n\t\t\t{\n\t\t\t\t// In this case we can use this number to extend the sequence\n\t\t\t\tcurSize++;\n\t\t\t\tlookingFor++;\n\t\t\t}\n\t\t\t// If we can\'t use this number and this number is greater than what we were looking for,\n\t\t\t// then we wont find what we are looking for (as the following numbers are only equal or greater)\n\t\t\telse if (nums[i] > lookingFor)\n\t\t\t{\n\t\t\t\t// Save off the size of the sequence we\'ve found so far\n\t\t\t\tmaxSize = max(maxSize, curSize);\n\n\t\t\t\t// Restart the sequence from this number, unless...\n\t\t\t\tcurSize = 1;\n\t\t\t\t// ...the previous numbers are a consecutive sequence\n                // that is exactly 1 less than what would lead to this number.\n\t\t\t\t// For example, with the numbers [...7, 11, 12, 13, 15, 16, ...],\n                // when we reach 15 we will reset the sequence (as we will be looking for 14),\n\t\t\t\t// but we can see that 11, 12, 13 are consecutive and could all be increased by 1\n                // to get the sequence 12, 13, 14 which then could be continued by 15.\n\t\t\t\tfor (int k = i - 1, target = nums[i] - 2; k >= 0 && target == nums[k]; --target, --k)\n\t\t\t\t\tcurSize++;\n\n\t\t\t\tlookingFor = nums[i] + 1;\n\t\t\t}\n\t\t}\n\t\t// Need to save off the last sequence we\'ve found\n\t\tmaxSize = max(maxSize, curSize);\n\n\t\treturn maxSize;\n\t}\n};\n```
['Sorting', 'C++']