Detailed Analysis with diff. Approaches
Intuition\nEach pair can have only 0,1,2 moves to get to any target_sum . \n\nWe can start iterating over all the pairs for each target_sum in range [2,2*limit]
# Intuition\nEach pair can have only 0,1,2 moves to get to any target_sum . \n\nWe can start iterating over all the pairs for each target_sum in range [2,2*limit] and find which gives min_moves to make array complementary. \n\n\n# Approach\nThe above idea isn\'t good due to time_constraints of the problem (O(n^2)).\n\nWe can try other way round , i.e. , pick each pair and iterate through all possible target_sum, correspondingly adding 0,1,2 to each target_sum idx.\n\nWe can improve more by dividing the possible target_sum into different regions for each pair ,and then use difference array concept.\n\nMore on this post : https://leetcode.com/problems/minimum-moves-to-make-array-complementary/solutions/953078/prefix-sum-o-n-limit-with-detailed-examples-and-pseudocode/\n\n\n# Code\n```\nclass Solution {\n    public int minMoves(int[] nums, int limit) {\n        int [] arr = new int[2*limit+2] ;\n\n        for (int i = 0; i < nums.length/2; i++) {\n            int l = nums[i] , r = nums[nums.length-1-i] ; \n            arr[0] += 2 ; \n            int one_move_min = Math.min(l,r)+1 ; \n            arr[one_move_min] -- ; \n            int just_good = l+r ; \n            arr[just_good] -- ; \n            arr[just_good+1] ++ ; \n            int one_move_max = Math.max(l,r)+limit ; \n            arr[one_move_max+1] ++ ; \n        }\n        int min_moves = Integer.MAX_VALUE ;\n        for (int i = 1; i < arr.length; i++) {\n            arr[i] += arr[i-1] ; \n            min_moves = Math.min(min_moves , arr[i]) ; \n        }\n        \n        return min_moves ; \n        \n        \n\n    }\n}\n```
['Prefix Sum', 'Java']