[C++] Simple Line Sweep Technique [Linear Time Complexity]
\nclass Solution {\npublic:\n    int minMoves(vector<int>& a, int limit) {\n        // each pair can provide a sum in a range of \n        // [l, r] => [min(a, 
```\nclass Solution {\npublic:\n    int minMoves(vector<int>& a, int limit) {\n        // each pair can provide a sum in a range of \n        // [l, r] => [min(a, b) + 1, max(a, b) + limit]\n        // __\n        //  ___\n        //  ______\n        //       ___\n        //         ___\n        //         ___\n        //         ___\n        //         ___\n        //         ___\n        //                  _____\n        //                            _____\n        // so basically each pair can provide some ranges like above\n        // and to make sum equal to one of the values of the ranges \n        // we need only 1 move for that particular pair\n        \n        int n = a.size();\n        vector<int> LineSweep(2e5, 0);\n        vector<int> sum(2e5, 0);\n        for(int i = 0; i < n/2; i++){\n            int mn = min(a[i], a[n - 1 - i]) + 1;\n            int mx = max(a[i], a[n - 1 - i]) + limit;\n            LineSweep[mx + 1]--;\n            LineSweep[mn]++;\n            sum[a[i] + a[n - 1 - i]]++;\n        }\n        for(int i = 1; i < 2e5; i++) {\n            LineSweep[i] += LineSweep[i - 1];\n        }\n        int res = n;\n        for(int possibleSum = 2; possibleSum < 2e5; possibleSum++){\n            res = min(res, n - LineSweep[possibleSum] - sum[possibleSum]);\n        }\n        return res;\n    }\n};\n```
['Line Sweep', 'C++']