Fixed sliding Window✔️✔️✅
Code\n\nclass Solution {\n    public int minSwaps(int[] nums) {\n        int ones = 0;\n        for (int num : nums) {\n            ones += num;\n        }\n\n 
# Code\n```\nclass Solution {\n    public int minSwaps(int[] nums) {\n        int ones = 0;\n        for (int num : nums) {\n            ones += num;\n        }\n\n        int n = nums.length;\n        int res = nums.length;\n        int left = 0, right = 0, cnt = 0;\n\n        // Create a sliding window of size \'ones\'\n        while (right < ones) {\n            cnt += nums[right % n];\n            right++;\n        }\n\n        // Calculate initial "holes" in the window\n        res = ones - cnt;\n\n        // Move the sliding window across the array\n        while (right < n + ones) {\n            cnt += nums[right % n];\n            cnt -= nums[left % n];\n            right++;\n            left++;\n            res = Math.min(res, ones - cnt);\n        }\n\n        return res;\n    }\n}\n\n```\n\n## Sliding window All 4 patterns covered\n\n[3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/solutions/5174962/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[1004. Max Consecutive Ones III](https://leetcode.com/problems/max-consecutive-ones-iii/solutions/5174824/dig-deep-into-sliding-window-pattern-two-pointers/)\n[1493. Longest Subarray of 1\'s After Deleting One Element](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/solutions/5182014/sliding-window-and-two-pointers/)\n[2348. Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays/solutions/5185486/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[2110. Number of Smooth Descent Periods of a Stock](https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/solutions/5185520/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[904. Fruit Into Baskets](https://leetcode.com/problems/fruit-into-baskets/solutions/5175513/deep-understanding-of-two-pointer-and-intuitive-problems/) **sliding window + Hashmap**\n[1358. Number of Substrings Containing All Three Characters](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/solutions/5180267/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[424. Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/solutions/5175013/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/solutions/5180407/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[1248. Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays/solutions/5175648/dig-deep-into-sliding-window-pattern-two-pointers/) **count SubArray payyern**\n[2537. Count the Number of Good Subarrays](https://leetcode.com/problems/count-the-number-of-good-subarrays/solutions/5185714/deep-understanding-of-two-pointer-and-intuitive-problems/)\n[992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/solutions/5175637/dig-deep-into-sliding-window-pattern-two-pointers/) **Very important Solution Must Read**\n[560. Subarray Sum Equals K](https://leetcode.com/problems/subarray-sum-equals-k/solutions/4416842/simple-as-that-important-pattern-must-read/)\n[713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/solutions/5182026/sliding-window-two-pointers/)\n[2302. Count Subarrays With Score Less Than K](https://leetcode.com/problems/count-subarrays-with-score-less-than-k/solutions/5185326/sliding-window-two-pointers-pattern/)\n[209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/solutions/5184815/sliding-window-two-pointers-pattern-4-minimum-shortest-valid-length/) **-- Read**\n[1234. Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string/solutions/5184770/sliding-window-and-two-pointers-pattern-4-shortest-minimum-valid-length/)\n[76. Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/solutions/5217464/sliding-window-two-pointers/)\n[567. Permutation in String](https://leetcode.com/problems/permutation-in-string/solutions/5181748/dig-into-deep-understanding/)\n[438. Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/solutions/5269110/must-read-5-types-of-patterns-sliding-window-and-two-pointers/)\n[239. Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/solutions/5175931/nge-pattern/)\n[1838. Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/solutions/5208112/understanding-sliding-window-and-two-pointers-intuition/)\n[1888. Minimum Number of Flips to Make the Binary String Alternating](https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating/solutions/5208326/minflips/)\n[1208. Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/solutions/5182062/sliding-window-two-pointers-pattern/)\n[1695. Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/solutions/5182119/sliding-window-two-pointers-pattern/)\n[2024. Maximize the Confusion of an Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam/solutions/5218273/sliding-window-and-two-pointer-pattern/)\n\n\n
['Java']