a few solutions
Let K be the quantity of 1s in the input array A.  Then we can append A onto itself (to consider the wrap-around case) and use a sliding window i..j of size K t
Let `K` be the quantity of 1s in the input array `A`.  Then we can append `A` onto itself (to consider the wrap-around case) and use a sliding window `i..j` of size `K` to count the 1s within the window.  The "cost" of swapping 1s into the 0s within the window is then the size of the window minus the count of 1s within the window, ie. `K - x`, which is the quantity of 0s within the window.  Thus it is a trivial optimization to count 0s within the window rather than using inversion to calculate it.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun minSwaps(A_: IntArray): Int {\n        var (N, K) = Pair(A_.size, A_.sum()!!)\n        var A = intArrayOf(*A_.copyOf(), *A_.copyOf())  // \u2B50\uFE0F to consider wrap-around\n        var x = A.slice(0 until K).sum()!!\n        var best = K - x\n        var (i, j) = Pair(0, K)\n        while (j < 2 * N) {\n            if (A[i++] == 1) --x\n            if (A[j++] == 1) ++x\n            best = Math.min(best, K - x)\n        }\n        return best\n    }\n}\n```\n\n*Javascript*\n```\nlet minSwaps = A => {\n    let N = A.length,\n        K = _.sum(A);\n    A.push(...A);  // \u2B50\uFE0F to consider wrap-around\n    let x = _.sum(A.slice(0, K)),\n        best = K - x;\n    let i = 0,\n        j = K;\n    while (j < 2 * N) {\n        if (A[i++]) --x;\n        if (A[j++]) ++x;\n        best = Math.min(best, K - x);\n    }\n    return best;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def minSwaps(self, A: List[int]) -> int:\n        N, K = len(A), sum(A)\n        A.extend(A[:])  # \u2B50\uFE0F to consider wrap-around\n        x = sum(A[:K])\n        best = K - x\n        i = 0\n        j = K\n        while j < 2 * N:\n            if A[i]: x -= 1\n            if A[j]: x += 1\n            best = min(best, K - x)\n            i += 1; j += 1\n        return best\n```\n\n*Rust*\n```\nimpl Solution {\n    pub fn min_swaps(A_: Vec<i32>) -> i32 {\n        let N = A_.len();\n        let K: i32 = A_.iter().sum();\n        let mut A = Vec::new();\n        for i in 1..=2 {\n            A.extend_from_slice(&A_);  // \u2B50\uFE0F to consider wrap-around\n        }\n        let mut x: i32 = *&A[..K as usize].iter().sum();\n        let mut best = K - x;\n        let mut i: usize = 0;\n        let mut j: usize = K as usize;\n        while j < 2 * N {\n            if A[i] == 1 { x -= 1; }\n            if A[j] == 1 { x += 1; }\n            best = std::cmp::min(best, K - x);\n            i += 1; j += 1;\n        }\n        return best;\n    }\n}\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    int minSwaps(VI& A) {\n        int N = A.size(),\n            K = accumulate(A.begin(), A.end(), 0);\n        A.insert(A.end(), A.begin(), A.end());  // \u2B50\uFE0F to consider wrap-around\n        auto x = accumulate(A.begin(), A.begin() + K, 0),\n             best = K - x;\n        auto i = 0,\n             j = K;\n        while (j < 2 * N) {\n            if (A[i++]) --x;\n            if (A[j++]) ++x;\n            best = min(best, K - x);\n        }\n        return best;\n    }  \n};\n```
[]