[C++] Two Pointer O(n) Solution
For finding a subarray with exactly k odd elements = count(subarray with at most k odd elements) - count(subarray with at most k-1 odd elements). This solution 
For finding a subarray with **exactly k odd elements = count(subarray with at most k odd elements) - count(subarray with at most k-1 odd elements)**. This solution consists of passing through the arrays twice (once for k odd elements and once for k-1 odd elements)\n\n```\nclass Solution {\n    \n    int atMostK(vector<int> &nums, int k){\n        \n        int len = nums.size();\n        int result = 0;\n        int start = 0;\n        int currOddCnt = 0;\n        \n        for(int end=0; end<len; end++){\n            //if the current element is odd\n            if(nums[end]&1) currOddCnt++;\n            \n            //if the number of odd elements in the window exceeds k -> start contarcting the window\n            while(start<=end && currOddCnt>k){\n                //reducing the count of odd numbers if the start of window is odd\n                if(nums[start]&1) currOddCnt--;\n                start++;\n            }\n            \n            //number of subarrays with at most k odd elements\n            result += end-start+1;\n        }\n        \n        return result;\n    }\n    \npublic:\n    int numberOfSubarrays(vector<int>& nums, int k) {\n        return atMostK(nums, k) - atMostK(nums, k-1);\n    }\n};\n```\n
[]