[JavaScript] Greedy, 3 Pointers - Time O(n), Space O(1)
\nvar minMoves = function(nums, k) {\n    let leftZeros = 0, rightZeros = 0, minMoves = Infinity, moves = 0, ones = 0, rightOnes = 0;\n    let i = 0;\n    for (
```\nvar minMoves = function(nums, k) {\n    let leftZeros = 0, rightZeros = 0, minMoves = Infinity, moves = 0, ones = 0, rightOnes = 0;\n    let i = 0;\n    for (; nums[i] == 0; i++);\n\n\t/* f -> front, b -> back, c -> center  */\n\n    for (let f = i, c = i, b = i; f < nums.length; f++) {\n        if (nums[f] == 1) {\n            ones++;\n            rightOnes++;\n            moves += rightZeros;\n        } else {\n            rightZeros++;\n        }\n\n        if (ones == k) {\n            while (c < f) {\n                if (nums[c] == 0) {\n                    const temp = moves + (k - rightOnes) - rightOnes;\n                    if (moves < temp)\n                        break;\n                    leftZeros++, rightZeros--;\n                    moves = temp;\n                } else\n                    rightOnes--;\n                c++;\n            }\n\n            minMoves = Math.min(minMoves, moves);\n            moves -= leftZeros;\n            ones--;\n\n            while (nums[++b] == 0)\n                leftZeros--;\n        }\n    }\n\n    return minMoves;\n};\n```
[]