99%/99% Python3 Solution
\n# Code\n\nclass Solution:\n    def maxSelectedElements(self, nums: List[int]) -> int:\n        nums.sort()\n        best = 1\n        prev_value = nums[0]\n  
\n# Code\n```\nclass Solution:\n    def maxSelectedElements(self, nums: List[int]) -> int:\n        nums.sort()\n        best = 1\n        prev_value = nums[0]\n        prev_low_streak = 1  # current streak if taking previous value as it is.\n        prev_high_streak = 1 # current streak if taking previous value +1.\n        for num in nums[1:]:\n            difference = num - prev_value\n            if difference == 0: # e.g. 11 then 11 so streak must be (11, 12)\n                prev_high_streak = prev_low_streak+1 # best streak as 12 is +1 the best streak as 11.\n            elif difference == 1: # e.g. 11 then 12, so either (11, 12) or (12, 13)\n                prev_low_streak = prev_low_streak+1 # best streak as 12 is +1 the best streak as 11.\n                prev_high_streak = prev_high_streak+1 # best streak as 13 is +1 the best streak as 12.\n            elif difference == 2: # e.g. 11 then 13, so streak must be (12, 13)\n                prev_low_streak = prev_high_streak+1 # best streak as 13 is +1 the best streak as 12.\n                prev_high_streak = 1  # possibly best streak will be started now from 14.\n            else:\n                prev_low_streak = 1\n                prev_high_streak = 1\n            best = max(best, prev_low_streak, prev_high_streak)\n            prev_value = num\n        return best\n```
['Python3']