Sliding Window | C++
\r\nclass Solution {\r\npublic:\r\n    int numberOfSubarrays(vector<int>& nums, int k) {\r\n        int n = nums.size(), dis = 1, i = 0, cnt = 0, ans = 0;\r\n  
```\r\nclass Solution {\r\npublic:\r\n    int numberOfSubarrays(vector<int>& nums, int k) {\r\n        int n = nums.size(), dis = 1, i = 0, cnt = 0, ans = 0;\r\n        vector<int> d(n + 1, 1);\r\n\r\n        for(int i=n-1; i>=0; i--) {\r\n            nums[i] % 2 ? dis = 1 : dis++;\r\n            d[i] = dis;\r\n        }\r\n       \r\n        for(int j=0; j<n; j++) {\r\n            if(nums[j] % 2) cnt++;\r\n\r\n            while(i <= j && cnt == k) {\r\n                ans += d[j + 1];\r\n                if(nums[i] % 2) cnt--;\r\n                i++;\r\n            }\r\n        }\r\n        return ans;\r\n    }\r\n};\r\n```
['Sliding Window', 'C++']