Sliding Window with edge case
\n\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        vector<int> res;\n        sort(stones.begin(),stones.end());\n  
\n```\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        vector<int> res;\n        sort(stones.begin(),stones.end());\n        int n = stones.size();\n        int l = 0, r = 0;\n        int result = 0;\n        while(l < n){\n            while(r < n && stones[r]-stones[l] < n){\n                r++;\n            }\n            if(r-l == n-1 && stones[r-1]-stones[l] == n-2){\n                result = max(r-l-1,result);\n            }\n            else\n                result = max(r-l,result);\n            r--;\n            l++;\n        }\n        res.push_back(n-result);\n        res.push_back(max(stones[n-2]-stones[0],stones[n-1]-stones[1])-n+2);\n        return res;\n    }\n};\n```
['C++']