[Java] line sweep solution
It\'s the same idea as problem 798 (Recommnad to make a check)\n\nWe would creat a boundary for each pair [l,r] by using 1 change. \nThen we would enumerate all
It\'s the same idea as problem 798 (Recommnad to make a check)\n\nWe would creat a boundary for each pair [l,r] by using 1 change. \nThen we would enumerate all possible complementary sum number. If that number in the boundary, it only need 0 or 1 change at most (possibly 0), otherwise, 2 change is need.\nAs we iterate over the possible sum, we can quickly calculate the need of change in o(1) by using line swap. Finally,  we can remove the repition (0 change pair)\n\n```\nclass Solution {\n    Map<Integer,Integer>map=new HashMap<>();\n    public int minMoves(int[] A, int limit) {\n        int n=A.length;\n        int res=Integer.MAX_VALUE;\n        int bound[][]=new int[n/2][2];\n        int line[]=new int[limit*2+10];\n        \n        for(int i=0;i<n/2;i++){\n            int mx=Math.max(A[i],A[n-i-1]);\n            int mn=Math.min(A[i],A[n-i-1]);\n            bound[i][0]=mx+limit;\n            bound[i][1]=mn+1;\n            \n            line[bound[i][0]+1]--;\n            line[bound[i][1]]++;\n            if(!map.containsKey(mx+mn)){\n                map.put(mx+mn,1);\n            }\n            else{\n                map.put(mx+mn,map.get(mx+mn)+1);\n            }\n        }\n        \n        \n        int sum=0;\n        for(int com=1;com<line.length;com++){\n            sum+=line[com];//1 move\n            int need=sum+(n/2-sum)*2;\n            int repeat=0;\n            if(map.containsKey(com)){\n                repeat=map.get(com);\n            }\n            res=Math.min(res,need-repeat);\n        }\n        \n        return res;\n    }\n}\n```
[]