ez
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.*;\n\nclass Solution {\n\n    // complementary array: (N always even)\n    // [a,b,c,d] a + d = b + c\n    // change to 1..LIMIT\n    // N/2 pairs; each pair is SEPARATE!!! no pair overlap!!\n    // max number of\n\n    // 1 <=  A[i]   <= limit\n    // 2 <= pairSum <= 2 * LIMIT\n\n    // each pair can be modified via:\n    // 0 changes => SAME pairsSum\n    // 1 changes => max(2, pairSum - LIMIT + 1) <= pairSum <= min(2 * LIMIT, pairSum + LIMIT - 1)\n    // 2 changes => 2 <= pairSum <= 2*LIMIT\n    public int minMoves(int[] A, int limit) {\n        int n = A.length, l = 0, r = n - 1, numPairs = n / 2;\n        int maxPairSum = 2 * limit;\n        int[] diff = new int[maxPairSum + 1];\n        while (l < r) {\n            int pairSum = A[l] + A[r];\n            int min = Math.min(A[l], A[r]);\n            int max = Math.max(A[l], A[r]);\n\n            int startOf2Left = 2;\n            int startOf1Left = min + 1;\n\n            int startOf1Right = pairSum + 1;\n            int startOf2Right = max + limit + 1;\n\n            diff[startOf2Left] += 2;\n            diff[startOf1Left]--;\n            diff[pairSum]--;\n            if (startOf1Right <= maxPairSum) diff[startOf1Right]++;\n            if (startOf2Right <= maxPairSum) diff[startOf2Right]++;\n\n            l++;\n            r--;\n        }\n\n        int minCost = n;\n        int currCost = 0;\n        for (int pairSum = 2; pairSum <= maxPairSum; pairSum++) {\n            currCost += diff[pairSum];\n            minCost = Math.min(minCost, currCost);\n        }\n        return minCost;\n    }\n    // [2,  3,  4, 5, 6] pairSum\n    // [8, -2, -1, 2, 5] diff\n\n    // limit = 3\n    // 1,3 = 4\n    // 3,1 = 4\n    // 1,3 = 4\n\n    // 1,2 = 3\n    // 1,1 = 2\n    // 2,3 = 5\n    // 2,3 = 5\n\n}\n\n```
['Java']