Easy C++ solution | no sliding window | O(N)
IntuitionWe store the indices of odd numbers and use basic math to calculate nice subarrays.Approach1]Store Indices of Odd numbers:
We traverse the array and st
# Intuition
We store the indices of odd numbers and use basic math to calculate nice subarrays.

# Approach
***1]Store Indices of Odd numbers:***
- We traverse the array and store the positions (indices) of all odd numbers.
- To handle boundaries, we add ```-1``` at the start and ```n``` (array size) at the end of this list.

***2]Group ```k``` Odd Numbers:***
- For each group of 𝑘 consecutive odd numbers, we want to count how many subarrays contain exactly these 𝑘 odd numbers.

***3]Calculate Gaps:***
- The gap before the first odd number in the group tells us how many even numbers (or positions) we can include at the start.
- The gap after the last odd number tells us how many even numbers (or positions) we can include at the end. We add 1 to each gap because we can also choose not to extend the subarray.

***4]Multiply and Sum:***
- For each group, multiply the two gap values. This multiplication gives the total number of ways to form a subarray that includes exactly ```k``` odd numbers. Finally, add up these values for all groups.

# Complexity
- Time complexity: $$O(n)$$ 
    - We iterate through ```nums``` once to store the indices of odd numbers (O(n)).
    - We then iterate over ```index``` (which has at most 𝑂(n) elements) to count subarrays (O(n)).
    - Thus, the total time complexity is O(n).

- Space complexity: $$O(n)$$
    - We use an auxiliary vector index to store the indices of odd numbers, which takes O(n) space in the worst case (all numbers are odd).

# Code
```cpp []
class Solution {
public:
    int numberOfSubarrays(vector<int>& nums, int k) {
        // declare ans as 0
        int ans = 0;

        // declare vector name index for storing indicies
        vector<int> index;

        // store indices of all odd numbers
        int n = nums.size();

        index.push_back(-1);
        for (int i = 0; i < n; i++) {
            // for checking odd numbers
            if (nums[i] % 2 != 0)
                index.push_back(i);
        }
        index.push_back(n);

        // add for all possible k odd numbers (before gap + 1) * (after gap + 1)
        //  where gap = index[i]-index[i-1] - 1 (so -1 & +1 get cancel out)
        int m = index.size();
        for (int i = 1; i < m; i++) {
            if (i + k >= m)
                break;
            ans += (index[i] - index[i - 1]) * (index[i + k] - index[i + k - 1]);
        }

        return ans;
    }
};
```
['Math', 'C++']