Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Group All 1's Together II

med
30 min
Try to solve the Minimum Swaps to Group All 1's Together II problem.

Statement

Given a binary circular array nums, you may perform swaps of any two elements in nums. Return the minimum number of swaps needed to make all values equal to 1 appear in a single contiguous block (considering the circular wrap around).

Note: Since nums is circular, a contiguous block of 1s may wrap from the end of the array to the beginning.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • nums[i] is either 00 or 11

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Group All 1's Together II

med
30 min
Try to solve the Minimum Swaps to Group All 1's Together II problem.

Statement

Given a binary circular array nums, you may perform swaps of any two elements in nums. Return the minimum number of swaps needed to make all values equal to 1 appear in a single contiguous block (considering the circular wrap around).

Note: Since nums is circular, a contiguous block of 1s may wrap from the end of the array to the beginning.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • nums[i] is either 00 or 11