C++ | 0ms - TC: 100% | Sliding Window
Intuition
the key observation is that we can perform 2 tasks:

we can either group all the 1s together
or we can group all the 0s together (this means that all
# Intuition
- the key observation is that we can perform 2 tasks: 
    - we can either group all the 1s together 
    - or we can group all the 0s together (this means that all the 1s are grouped together in the circular array)
# Approach
- we use sliding window to find the swaps required to get all the 1s together and all the 0s together
    - step 1 : count the total number of 1s in the array this is our target aka `k`
    - initialize the pointers to the window `start` and `end` = `0`
    - now we start expanding the window using `end++`
    - if the total count of the digits(`ones`+`zeroes`) becomes equal to the value `k` then we count all the `0`s in the window, this is the minimum number of swaps required for the current window. We keep track of the result in variable `res` and perform res = `min(res,zeroes)`
    - next if we have ateast k digits we slide the window by performing `++start`
- We repeat this entire process but for `0s` instead of `1s` (because doing this will give us the minimum number of swaps for the 1s to be on the edges and since its a circular array they are grouped together -> Eg: `111100000111` all the 0s are grouped together and by default this pushes all the 1s to the edges and hence are grouped).  

# Complexity
- Time complexity:
O(n) , n = length of the array
- Space complexity:
O(1) , constant space

# Code
```cpp []
class Solution {
public:
    int minSwaps(vector<int>& nums) {

        // k : indicates the total number of 1s we want together    
        int k = 0 ;
        for(int x : nums) k += x == 1 ;
        
        // we use sliding window ok size k to find the total number of 1s and 0s
        // if there are x 0s in the window we need to swap them with 1s instead 
        // hence res = min(res,zeroes) ;
        int start = 0 , end = 0 ;
        int ones = 0, zeroes = 0 ;
        int res = INT_MAX ;
        while(end < nums.size()){
            
            ones += nums[end] == 1 ;
            zeroes += nums[end] == 0 ;
            ++end ;

            // if we have found the limit, slide the window
            if(ones + zeroes >= k){
                res = min(res,zeroes) ;
                ones -= nums[start] == 1 ;
                zeroes -= nums[start] == 0 ;
                ++start ;
            }

        }

        // perform the same operation but this time for 0s instead of 1s
        k = 0 ;
        for(int x : nums) k += x == 0 ;
        
        start = 0 , end = 0 ;
        ones = 0, zeroes = 0 ;
        while(end < nums.size()){
            ones += nums[end] == 1 ;
            zeroes += nums[end] == 0 ;
            ++end ;
            if(ones + zeroes >= k){
                res = min(res,ones) ;
                ones -= nums[start] == 1 ;
                zeroes -= nums[start] == 0 ;
                ++start ;
            }
        }

        return res ;
    }
};
```
['Sliding Window', 'C++']