[Java] Code with Explaination
\n\tclass Solution {\n    public int minMoves(int[] nums, int limit) {\n        int[] delta = new int[2*limit + 2];\n        int n = nums.length;\n        // ma
````\n\tclass Solution {\n    public int minMoves(int[] nums, int limit) {\n        int[] delta = new int[2*limit + 2];\n        int n = nums.length;\n        // max move to make array complement is n, if we replace all element\n        // considering moving a and move b, so for a pair we need 2 move\n        int move = n;\n        for(int i=0;i<n/2;i++){\n            int a = nums[i];\n            int b = nums[n-1-i];\n            int min = Math.min(a,b);\n            int max = Math.max(a,b);\n            \n            int minSumWithOneMove = min + 1 ; // replacing max element to 1 : a = min , b = 1\n            int maxSumWithOneMove = max + limit ; // replacing min element to limit : a = max , b = limit\n            \n            // incase we our sum is within minSumWithOneMove and maxSumWithOneMove\n            // we need only one move, previously we assumed two move for each pair\n            // so we need to decrease by 1 move \n           \n            delta[minSumWithOneMove]--;\n            \n            // if our target sum is a+b then we don\'t need any move so, we need to decrease it by 1, so that \n            // cumulative decrease move will be by 2, one for range another for being exact same target\n           \n            delta[a+b]--;\n            \n            // if our sum is greater than a+b, then we need only one move, as cummulative move decreased by 2\n            // we need to increase a+b+1 by 1, so that it restores to one move from 2 move\n           \n            delta[a+b+1]++;\n            \n            // if target sum exceed maxSumWithOneMove, then we need to 2 move because to achieve target\n            // we need to replace both a and b, so, we need to incease maxSumWithOneMove + 1 by 1\n            // so that cumulative move increase to 2 again\n            \n            delta[maxSumWithOneMove+1]++;\n            \n        }\n        \n        // we need to calculate min move, our max Move is n\n        // add all moves from 2 to 2*limit+1 and return min Move\n       \n        int minMove = n;\n        for(int i=2;i<=2*limit+1;i++){\n            \n            move+=delta[i];\n            minMove = Math.min(minMove, move);\n        }\n         \n        return minMove;\n    }\n}\n\n````\n\nrefer discussion for better understanding : https://leetcode.com/problems/minimum-moves-to-make-array-complementary/discuss/953078/Prefix-sum-O(n-%2B-limit)-with-detailed-examples-and-pseudocode
[]