JS
Code\n\nvar minSwaps = function (nums) {\n    let n = nums.length;\n    let x = nums.reduce((x, e) => x + e, 0);\n\n    let max = -Infinity, y = 0;\n    for (le
# Code\n```\nvar minSwaps = function (nums) {\n    let n = nums.length;\n    let x = nums.reduce((x, e) => x + e, 0);\n\n    let max = -Infinity, y = 0;\n    for (let z = 0, a = -x; z < n + x; z++, a++) {\n        y += nums[z % n];\n        if (a >= 0) {\n            y -= nums[a % n];\n        }\n        max = Math.max(max, y);\n    }\n    return x - max;\n};\n```
['JavaScript']