2
public int numberOfSubarrays(int[] nums, int k) {10
Approach : two pointer + sliding window technique12
step 1 : we have fix i and moving j until our count of odd numbers == k13
step 2 : when(odd == count) we are counting every possible subarray by reducing the size of subarray from i16
from reducing the size of subarray we will count all the possible subarray from between i and j17
but when i encounter a odd element the odd count will reduce and that while will stop executing19
now there are two possible cases20
1.The leftover elements have a odd number21
2.The leftover elements do not have any odd number23
1. if our leftover elements have a odd number24
then we cannot include our old possible subarrays into new possible subarrays because now new window for having odd == k is formed27
2. if out leftover elements do not have any odd element left28
then our leftover elements must also take in consideration becuase they will also contribute in forming subarrays30
while (j < nums.length) {31
if (nums[j] % 2 != 0) {33
// if leftover elements have odd element then new window is formed so we set temp = 0;38
if (nums[i] % 2 != 0) odd--;41
// if no leftover elements is odd, each element will part in forming subarray