# Leetcode 2134: Minimum Swaps to Group All 1’s Together II

2 min readJan 10, 2022

--

In this exercise, we try to put all the ones together in a circular array by swapping elements. We need to find the minimum number of swaps needed:

A

swapis defined as taking twodistinctpositions in an array and swapping the values in them.

Acirculararray is defined as an array where we consider thefirstelement and thelastelement to beadjacent.

Given abinarycirculararray`nums`

, returnthe minimum number of swaps required to group all`1`

's present in the array together at.any location