Java | Two-Pointer & Sliding window | Time: O(N) & Space: O(1)
\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n     \n        int odds = 0;\n        int i = 0, j = 0, flag = 0;\n        int n = nu
```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n     \n        int odds = 0;\n        int i = 0, j = 0, flag = 0;\n        int n = nums.length;\n        int ans = 0;\n        while(j < n){\n            if(nums[j]%2!=0){\n                odds++;\n            }\n            while(odds > k){\n                if(nums[i++]%2!=0)odds--;\n                flag = i;\n            }\n            if(odds == k){\n                ans+=(i+1-flag);\n                while(nums[i]%2==0){\n                    i++;\n                    ans++;\n                }\n            }\n            j++;\n        }\n        return ans;\n    }\n}\n```
['Java']