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 swap is defined as taking two distinct positions in an array and swapping the values in them.
A circular array is defined as an array where we consider the first element and the last element to be adjacent.
Given a binary circular arraynums
, return the minimum number of swaps required to group all1
's present in the array together at any location.