c++ , explained
First we need understand the cost associated with each pair. Let us call "target" as nums[i]+nums[n-i-1] after we make array complimentary.\nLet mi = min(nums[i
First we need understand the cost associated with each pair. Let us call "target" as nums[i]+nums[n-i-1] after we make array complimentary.\nLet mi = min(nums[i],nums[n-i-1]) and ma =max(nums[i],nums[n-i-1])\nif (target<mi+1) , cost =2\nif (mi+1<=target<=mi+ma-1) , cost =1\nif (target = mi+ma) , then cost =0\nif (mi+ma+1<=target<=limit+ma) , cost =1\nif (target>ma+1+limit) , cost =2\n\nnow we create a vector v1 which will provide us the cost for every possible value of target (although target != 0 or 1, but i have included that for simplicity) . Here for each pair we update the vector in the following way \nv1[0]+=2   this is for the 1st case given above, \nv1[mi+1]+=-1   then from mi+1 our cost is reduced (2-> 1) {case 2}\nv1[mi+ma]+= -1    at mi+ma we dont need to make changes in nums hence cost reduced(1->0){case 3}\nv1[mi+ma+1]+= 1  soon after the mi+ma point our cost is increased (0->1) {case 4}\nv1[ma+limit+1]+=1   represents case 5, cost increases(1->2)\n\n\nFinally we take prefix sum of this vector and find min value of the cost\n\n```\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int limit) {\n        int n = nums.size();\n       vector<int> v1(2*limit+2,0);\n        for(int i=0;i<n/2;i++)\n        {\n            int mi = min(nums[i],nums[n-1-i]);\n            int ma = max(nums[i],nums[n-1-i]);\n            v1[0]+=2;\n            v1[mi+1]+=-1;\n            v1[mi+ma]+=-1;\n            v1[mi+ma+1]+=1;\n            v1[ma+limit+1]+=1;   \n        }\n        int ans= INT_MAX;\n        for(int i=1;i<v1.size();i++)\n        {    v1[i]+=v1[i-1];\n            ans =min(ans,v1[i]);\n        }\n        return ans;   \n        \n    }\n};\n```\n
[]