Solution Maximize Consecutive Elements in an Array After Modification
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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 {\n    /**\n     * @param Integer[] $nums\n     * @return Integer\n     */\n    function maxSelectedElements($nums) {\n        sort($nums);\n        \n        $dp1 = array_fill(0, count($nums), 1);\n        $dp2 = array_fill(0, count($nums), 1);\n        \n        $max = 1;\n        \n        for ($i = 1; $i < count($nums); $i++) {\n            if ($nums[$i - 1] + 1 === $nums[$i]) {\n                $dp1[$i] = $dp1[$i - 1] + 1;\n                $dp2[$i] = $dp2[$i - 1] + 1;\n            } elseif ($nums[$i] === $nums[$i - 1]) {\n                $dp2[$i] = max($dp1[$i - 1] + 1, $dp2[$i - 1]);\n            } elseif ($nums[$i - 1] + 2 === $nums[$i]) {\n                $dp1[$i] = $dp2[$i - 1] + 1;\n            }\n            $max = max($max, $dp1[$i], $dp2[$i]);\n        }\n        \n        return $max;\n    }\n}\n```
['PHP']