cpp14 solution
max idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286920/Use-Interval-to-Get-Max-Moves\n\nmin idea : https://leetcode.com/prob
max idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286920/Use-Interval-to-Get-Max-Moves\n\nmin idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/555907/C%2B%2B-solution-or-Sliding-window-for-minimum-moves\n\n\n```\nclass Solution {\npublic:\n\n    int calculatemax(vector<int> &stones)\n    {\n        vector<int> intervals;\n        for(int i = 1 ; i < stones.size() ; ++i){\n            intervals.push_back(stones[i] - stones[i-1] - 1);\n        }\n        int maxx = 0;\n        if(intervals[0] != 0 and intervals[intervals.size()-1] != 0){\n            if(intervals[0] > intervals[intervals.size() -1]){\n                intervals.pop_back();\n            }\n            else{\n                intervals.erase(intervals.begin());\n            }\n        }\n        maxx = accumulate(intervals.begin() , intervals.end() , 0);\n        return maxx;\n    }\n\n    int calculatemin(vector<int> &stones)\n    {\n        int i = 0 , j = 0;\n        int minn = INT_MAX;\n        int n = stones.size() ; \n        while(1){\n            if(j >= n or i >= n) break;  \n            int windowsize = stones[j] - stones[i] + 1;\n            int totalstones = j - i + 1;\n            if(windowsize > n){\n                ++i;\n                continue;\n            }\n            if(windowsize == n-1 and totalstones == n-1){\n                minn = min(minn , 2);\n            }\n            else{\n                minn = min(minn , n - totalstones);\n            }\n            ++j;\n        }\n        return minn;\n    }\n\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        sort(stones.begin() , stones.end());\n        int maxx = calculatemax(stones);\n        int minn = calculatemin(stones);\n        vector<int> res = {minn , maxx} ;\n        return res;\n    }\n};\n\n```
[]