Two Pointer Solution easy
\r\n\r\n# Approach\r\n Describe your approach to solving the problem. \r\nIn this solution we basically take 2 pointers (i and j). If the nums[j] is odd we incr
\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\nIn this solution we basically take 2 pointers (i and j). If the nums[j] is odd we increase the odd counter. If off is equal to k we count all the subarrays in between i and j by increasing i position till odd == k. We add the result in res.\r\n\r\n\r\n# Code\r\n```\r\nclass Solution {\r\n    public int numberOfSubarrays(int[] nums, int k) {\r\n        int i=0,j=0,odd=0,count=0,res=0;\r\n        while(j<nums.length){\r\n            if(nums[j]%2!=0){\r\n                odd++;\r\n                count=0;\r\n            }\r\n            while(odd==k){\r\n                if(nums[i++]%2!=0){\r\n                    odd--;\r\n                }\r\n                count++;\r\n            }\r\n            res+=count;\r\n            j++;\r\n        }\r\n        return res;\r\n    }\r\n}\r\n```
['Two Pointers', 'Java']