[Java/C++/Python] Solution
Short Explanation\nFind all index of nums[i] if nums[i] == 1.\nNow the problem changes to,\nfind k consecute element in A,\nthat has minimum distance to their m
# **Short Explanation**\nFind all index of `nums[i]` if `nums[i] == 1`.\nNow the problem changes to,\nfind `k` consecute element in `A`,\nthat has minimum distance to their median sequence.\nTo solve this, we need to use the prefix sum of `A`,\nwhich is `B` in this solution.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public int minMoves(int[] nums, int k) {\n        ArrayList<Long> A = new ArrayList<Long>(), B = new ArrayList<Long>();\n        for (int i = 0; i < nums.length; ++i)\n            if (nums[i] == 1)\n                A.add((long)i);\n        long res = Long.MAX_VALUE;\n        B.add(0L);\n        for (int i = 0; i < A.size(); ++i)\n            B.add(B.get(i) + A.get(i));\n        for (int i = 0; i <  A.size() - k + 1; ++i)\n            res = Math.min(res, B.get(i + k) - B.get(k / 2 + i) - B.get((k + 1) / 2 + i) + B.get(i));\n        res -= (k / 2) * ((k + 1) / 2);\n        return (int)res;\n    }\n```\n**C++:**\n```cpp\n    int minMoves(vector<int>& nums, int k) {\n        vector<long> A, B(1);\n        for (int i = 0; i < nums.size(); ++i)\n            if (nums[i])\n                A.push_back(i);\n        long n = A.size(), res = 2e9;\n        for (int i = 0; i < n; ++i)\n            B.push_back(B[i] + A[i]);\n        for (int i = 0; i < n - k + 1; ++i)\n            res = min(res, B[i + k] - B[k / 2 + i] - B[(k + 1) / 2 + i] + B[i]);\n        res -= (k / 2) * ((k + 1) / 2);\n        return res;\n    }\n```\n\n**Python:**\n```py\n    def minMoves(self, A, k):\n        A = [i for i, a in enumerate(A) if a]\n        n = len(A)\n        B = [0] * (n + 1)\n        res = float(\'inf\')\n        for i in xrange(n):\n            B[i + 1] = B[i] + A[i]\n        for i in xrange(len(A) - k + 1):\n            res = min(res, B[i + k] - B[k / 2 + i] - B[(k + 1) / 2 + i] + B[i])\n        res -= (k / 2) * ((k + 1) / 2)\n        return res\n```\n
[]