✅ Easy C++ Solution
Code\n\nclass Solution {\npublic:\n    int subarray(vector<int> nums, int k)\n    {\n        if(k < 0)\n        {\n            return 0;\n        }\n        int
# Code\n```\nclass Solution {\npublic:\n    int subarray(vector<int> nums, int k)\n    {\n        if(k < 0)\n        {\n            return 0;\n        }\n        int n = nums.size();\n\n        int l = 0;\n        int r = 0;\n        int odd = 0;\n        int count = 0;\n\n        while(r < n)\n        {\n            if(nums[r] % 2)\n            {\n                odd++;\n            }\n            while(odd > k)\n            {\n                if(nums[l] % 2)\n                {\n                    odd--;\n                }\n                l++;\n            }\n            count = count + (r-l+1);\n            r++;\n        }\n        return count;\n    }\n\n    int numberOfSubarrays(vector<int>& nums, int k) {\n        return subarray(nums,k) - subarray(nums, k-1);\n    }\n};\n```
['C++']