Classic Sliding Window Question
Basic Idea: Find the total no. of ones in the given array. Now make a sliding window of that size. Window with maximum no. of ones will require the minimum numb
**Basic Idea:** Find the total no. of ones in the given array. Now make a sliding window of that size. Window with maximum no. of ones will require the minimum number of swaps.\n\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n    int n = nums.size();\n    int count_1 = count(nums.begin(), nums.end(), 1);\n\n    if (count_1 == 0 || count_1 == n) {\n        return 0;\n    }\n\n\n    int current_ones = 0;\n    for (int i = 0; i < count_1; i++) {\n        current_ones += nums[i];\n    }\n    int max_ones = current_ones;\n\n    for (int i = 1; i < n; i++) {\n        current_ones = current_ones - nums[i - 1] + nums[(i + count_1 - 1) % n];\n        max_ones = max(max_ones, current_ones);\n    }\n\n    int min_swaps_needed = count_1 - max_ones;\n\n    return min_swaps_needed;\n    }\n};\n```
['C']