Solution Moving Stones Until Consecutive
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    /**\n     * @param Integer[] $stones\n     * @return Integer[]\n     */\n    function numMovesStonesII($stones) {\n        sort($stones);\n        $n = count($stones);\n        $total = $stones[$n - 1] - $stones[0] + 1 - $n;\n        \n        $maxMoves = max($stones[$n - 1] - $stones[1] - $n + 2, $stones[$n - 2] - $stones[0] - $n + 2);\n        \n        $left = 0;\n        $minMoves = $n;\n        \n        for ($right = 0; $right < $n; $right++) {\n            while ($stones[$right] - $stones[$left] >= $n) {\n                $left++;\n            }\n            \n            if ($right - $left + 1 === $n - 1 && $stones[$right] - $stones[$left] === $n - 2) {\n                $minMoves = min($minMoves, 2);\n            } else {\n                $minMoves = min($minMoves, $n - ($right - $left + 1));\n            }\n        }\n        \n        return [$minMoves, $maxMoves];\n    }\n}\n\n```
['PHP']