beats 100%
Intuition\nC++\n\nPython3\n\n\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nSimply Use the queue to store the indexes of odd el
# Intuition\nC++\n![image.png](https://assets.leetcode.com/users/images/cb255a61-1ed9-4d04-b002-6fe32cbff145_1719055212.2930067.png)\nPython3\n![image.png](https://assets.leetcode.com/users/images/d22e213a-ebd5-428e-bcbc-a3bf719b30e2_1719055325.17195.png)\n\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSimply Use the queue to store the indexes of odd elements.\nStart counting the subarrays when the Queue is of K size.\nMaintain two variables end and last to count the values that can be added to next index.\n# Complexity\n- Time complexity:\nOnly one iterations, e.g. O(n)\n- Space complexity:\nA Queue with max of k elements, e.g. O(k)\n\n# Code C++\n```\nclass Solution {\npublic:\n    int numberOfSubarrays(vector<int>& nums, int k) {\n        ios::sync_with_stdio(false);\n        cin.tie(0);\n        cout.tie(0);\n        queue<int> Q;\n        int lst = 0, end = -1, ans = 0;\n        for (int i = 0; i < nums.size(); i++) {\n            if(nums[i]&1){\n                Q.push(i);\n            }\n            if(Q.size() == k){\n                lst = end;\n                end = Q.front();\n                Q.pop();\n            }\n            if(end != -1){\n                ans += end - lst;\n            }\n        }\n        return ans;\n    }\n};\n//if you upvote this you will hear good news in 10mins\n```\n# Code Python3\n```\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        odd_count = 0\n        res = 0\n        i = 0\n        count = 0\n        for ele in nums:\n            if ele % 2 == 1:\n                odd_count += 1\n                count = 0\n\n            while odd_count==k:\n                if nums[i] % 2 == 1:\n                    odd_count -= 1\n                i += 1\n                count += 1\n                \n            res += count\n        return res\n#if you upvote this you will hear good news in 10mins\n```
['C++', 'Python3']