Sliding window + deque. One pass
\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        ans, left, que = 0, -1, deque()\n        for i in range(len(nums)):
```\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        ans, left, que = 0, -1, deque()\n        for i in range(len(nums)):\n            if nums[i]%2:\n                que.append(i)\n                if len(que) > k:\n                    left = que.popleft()\n            if len(que) == k:\n                ans += que[0]-left\n        return ans\n```\n> Alternative solution without deque (a bit slower)\n```\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        ans, left, cnt = 0, 0, 0\n        for i in range(len(nums)):\n            if nums[i]%2:\n                k -= 1\n                cnt = 0\n            while k <= 0:\n                k += nums[left]%2\n                left += 1\n                cnt += 1\n            ans += cnt\n        return ans\n```
['Sliding Window', 'Python3']