C++| Sliding Window for min + Greedy for max | O(n)
\nclass Solution {\npublic:\n    int cal_min(vector<int>& nums){\n        unordered_map<int,int> mp; \n        int left = 0, m = INT_MAX;\n        for(int i = 0
```\nclass Solution {\npublic:\n    int cal_min(vector<int>& nums){\n        unordered_map<int,int> mp; \n        int left = 0, m = INT_MAX;\n        for(int i = 0; i<nums.size();++i) mp[nums[i]] = i;\n        for(int i = 0; i<nums.size();++i){\n            int e = nums[i]+nums.size()-1;\n            if(e>nums[nums.size()-1]) continue;\n            int n = nums.size()-(upper_bound(nums.begin(),nums.end(),e)-nums.begin());\n            if(left || mp.find(e)!=mp.end() || n>1) m = min(left+n,m);\n            left++;\n        }\n        return m;\n    }\n    int cal_max(vector<int>& nums){\n        int sum = 0,n = nums.size();\n        for(int i = 1; i<nums.size();++i) sum+=(nums[i]-nums[i-1]-1);\n        int a = nums[1]-nums[0]-1, b = nums[n-1]-nums[n-2]-1;\n        return sum - min(a,b);\n    }\n    vector<int> numMovesStonesII(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        return {cal_min(nums),cal_max(nums)};\n    }\n};\n```
['C', 'Sliding Window']