C++ O(N log(N))
\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        int N= stones.size(), max_in_N=0, min_steps, max_steps, first_gap;
```\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        int N= stones.size(), max_in_N=0, min_steps, max_steps, first_gap;\n        \n        if(N<3) return {0,0};\n        \n        sort(stones.begin(), stones.end());\n        \n        for(int i=0, j=0; i<N; ++i){\n            while( j < N && stones[i] + N  > stones[j]) ++j;\n            max_in_N= max(max_in_N, j-i);\n        }\n        \n        min_steps= N - max_in_N ;\n        \n        if(max_in_N==N-1 && N>3 && max(stones[1]-stones[0], stones[N-1]-stones[N-2]) > 2) min_steps= 2;\n        \n        \n        first_gap= min(stones[1]-stones[0], stones[N-1]-stones[N-2]);\n        max_steps= (stones[N-1] - stones[0] + 1) - N - (first_gap - 1);\n        \n        return {min_steps, max_steps};\n    }\n};\n```
[]