javascript 132ms
reference: https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones/discuss/987347/JavaC%2B%2BPython-Solution\n\nconst minMoves = (nums, k) =
reference: https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones/discuss/987347/JavaC%2B%2BPython-Solution\n```\nconst minMoves = (nums, k) => {\n    let N = nums.length;\n    let one = [];\n    for (let i = 0; i < N; i++) {\n        if (nums[i] == 1) one.push(i);\n    }\n    let n = one.length;\n    let pre = preSum(one, n);\n    let res = Infinity;\n    for (let i = 0; i < n - k + 1; i++) {\n        res = Math.min(res, pre[i + k] - pre[(k >> 1) + i] - pre[(k + 1 >> 1) + i] + pre[i]);\n    }\n    res -= (k >> 1) * (k + 1 >> 1);\n    return res;\n};\n\n////////////////////////////// any of them will get the same prefix sum like this [0, 0, .......] //////////////\nconst preSum = (a, n) => {\n    let pre = [0];\n    for (let i = 0; i < n; i++) {\n        pre.push(pre[i] + a[i]);\n    }\n    return pre;\n};\n\nconst preSum = (a, n) => {\n    let pre = [a[0]];\n    for (let i = 1; i < n; i++) {\n        pre[i] = pre[i - 1] + a[i];\n    }\n    pre.unshift(0);\n    return pre;\n};\n\nconst preSum = (a, n) => {\n    let pre = Array(n + 1).fill(0);\n    for (let i = 0; i < n; i++) {\n        pre[i + 1] = pre[i] + a[i];\n    }\n    return pre;\n};\n\nconst preSum = (a, n) => {\n    let pre = Array(n + 1).fill(0);\n    for (let i = 1; i <= n; i++) {\n        pre[i] = pre[i - 1] + a[i - 1];\n    }\n    return pre;\n};\n```
[]