Minimum Swaps to Group Circular Ones
Problem statement
Given a circular binary array nums, return the minimum number of swaps between any two positions needed to group all 1s into one contiguous circular block.
Function
minSwapsCircularOnes(nums: int[]) → intExamples
Example 1
nums = [0,1,0,1,1,0,0]return = 1Example 2
nums = [1,1,0,0,1]return = 0Constraints
1 <= nums.length <= 100000.- Every value is
0or1.