Java, prefix sum
\npublic int minMoves(int[] nums, int k) {\n        List<Integer> indices = IntStream.range(0, nums.length).filter(i->nums[i] == 1).mapToObj(i -> i).collect(Col
```\npublic int minMoves(int[] nums, int k) {\n        List<Integer> indices = IntStream.range(0, nums.length).filter(i->nums[i] == 1).mapToObj(i -> i).collect(Collectors.toList());\n        int pSum[] = new int[indices.size() + 1]; // 1-indexed prefix sums\n        for (int i = 0; i < indices.size(); ++i) pSum[ i + 1 ] += indices.get(i) + pSum[ i ];\n        int ans = Integer.MAX_VALUE, right = k - 1;\n        while (right < indices.size()) {\n            int left = right - k + 1;\n            int m = left +  ( k + 1 ) / 2 - 1; \n            int radius = m - left;\n            int res = ( pSum[ right + 1 ] - pSum[ m + 1 ] ) - ( pSum[ m ] - pSum[ left ] ) -  radius * ( radius + 1 ); \n            if (k % 2 == 0) res -=  indices.get( m )  + ( radius + 1); \n            ans = Math.min(ans, res);\n            right++;\n        }\n        return ans;\n    }\n```
[]