dsa · medium
Min Swaps to Group All 1s
GreyOrangeArraySliding Window
Binary array data. Return the minimum swaps to group all 1s together (they may wrap? **no wrap**).
Arguments
data— the input array
**Example**
`` Input: [1,0,1,0,1] Output: 1 ``
Constraints
1 <= data.length <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,0,1,0,1] Expected: 1
Example 2
Input: [0,0,0,1,0] Expected: 0