Free written solution

Minimum Swaps to Group All 1's Together II (LeetCode 2134): Solution and Explanation

Given a binary circular array, find the fewest swaps that gather every 1 into one contiguous block, where the block may wrap from the end of the array back to the start.

Read the intuition, approach, code and complexity →