C++ Sliding Window Solution O(1) Space
Similar to https://leetcode.com/problems/subarrays-with-k-different-integers/\n\npublic:\n    int numarr(vector<int>&nums,int k){\n        int ans=0;\n        i
Similar to https://leetcode.com/problems/subarrays-with-k-different-integers/\n```\npublic:\n    int numarr(vector<int>&nums,int k){\n        int ans=0;\n        int count=0;\n        int i=0,j=0,n=nums.size();\n        while(j<n){\n            if(nums[j]%2==1){\n                count++;\n            }\n            if(count>k){\n                while(i<=j && count>k){\n                    if(nums[i]%2==1){\n                        count--;\n                    }\n                    i++;\n                }\n            }\n            ans+=(j-i+1);\n            j++;\n        }\n        return ans;\n    }\n    int numberOfSubarrays(vector<int>& nums, int k) {\n        return numarr(nums,k)-numarr(nums,k-1);\n    }\n};\n```
[]