C++| 🚀 ✅ Sliding Window | 🚀 ✅ With Explaination | 🚀 ✅ Easy to Understand
Intuition:\r\nThe problem requires finding the number of subarrays having exactly k odd integers. We can solve the problem using sliding window technique where 
# Intuition:\r\nThe problem requires finding the number of subarrays having exactly k odd integers. We can solve the problem using sliding window technique where we maintain a window of contiguous subarray and slide it from left to right. While sliding the window, we keep track of the number of odd integers inside the window and count the number of subarrays having exactly k odd integers.\r\n\r\n# Approach:\r\nWe initialize two pointers, start and end, to the first element of the array. We also initialize count to zero and ans to zero. We then traverse the array using the end pointer and for each element, we increment count if it is odd. We then slide the window to the right until count becomes equal to k. At each step, we update ans with the number of subarrays having exactly k odd integers. Finally, we return ans.\r\n\r\nTo find the number of subarrays having exactly k odd integers, we subtract the number of subarrays having less than k odd integers from the number of subarrays having at most k-1 odd integers. We can reuse the same subArray function to compute both.\r\n\r\n# Complexity:\r\n- Time complexity: O(n), where n is the size of the array. We traverse the array only once.\r\n- Space complexity: O(1), as we use constant extra space.\r\n\r\n# Code\r\n```\r\nclass Solution {\r\npublic:\r\n    int subArray(vector<int>& nums, int k) {\r\n        int count = 0, ans = 0, start = 0, end = 0;\r\n        int n = nums.size();\r\n        while(end<n){\r\n            if(nums[end]%2==1){\r\n                count++;\r\n            }\r\n            while(count>k){\r\n                if(nums[start]%2==1){\r\n                    count--;\r\n                }\r\n                start++;\r\n            }\r\n            ans += end-start+1;\r\n            end++;\r\n        }\r\n        return ans;\r\n    }\r\n    int numberOfSubarrays(vector<int>& nums, int k) {\r\n      return subArray(nums, k) - subArray(nums, k - 1);\r\n    }\r\n};\r\n```
['Sliding Window', 'C++']