Easy implementation || beats 97.42%
Intuition\n\n Describe your first thoughts on how to solve this problem. \nUse fixed size sliding window technique in which size of the window is total number o
# Intuition\n![Screenshot 2024-02-03 172316.png](https://assets.leetcode.com/users/images/44f48985-3975-49be-a40a-4c04fdcf08ac_1706961711.5296783.png)\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse fixed size sliding window technique in which size of the window is total number of 1\'s(k) in the array , to avoid overhead of circular array we can append the first k elements to given array or whole array would also work here.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust go through the window and compute the minimum number of zeros in the window .\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n+k)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(k)\n# Code\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n      int i=0,j=0,k=0;\n      for(auto it:nums) if(it) k++;\n      if(k==0) return 0;\n      int ans=1e6,zero=0;\n      for(int x=0;x<k;x++) nums.push_back(nums[x]);\n      int n=nums.size(); \n      while(j<n){\n          if(!nums[j]) zero++;\n          if(j-i+1<k) j++;\n          else if(j-i+1==k){\n              ans=min(ans,zero);\n              if(!nums[i]) zero--;\n              i++;\n              j++;\n          }\n      }  \n      return ans;\n    }\n};\n```
['Sliding Window', 'C++']