O(n) solution
In the example [2,2,2,1,2,2,1,2,2,2] for k = 2 the first element of a nice subarray can be the first 1 or any 2 before it and the last element can be the second
In the example [2,2,2,1,2,2,1,2,2,2] for k = 2 the first element of a nice subarray can be the first 1 or any 2 before it and the last element can be the second 1 or any 2 after it. We transform this array to [4,3,4] (every number in the new array is the length of subarray of even numbers plus 1). The answer is 16 = 4 (any of the 3 even numbers + 1 odd number at the right end of subarray of even numbers) * 4 (1 odd number at the left end of subarray + any of the 3 even numbers). In general case the distance between multipliers is k for resulting subarray to contain exactly k odd numbers.\n\n\n```\n    int numberOfSubarrays(vector<int>& nums, int k)\n    {\n        int count = 0;\n        vector<int> groups;\n        groups.push_back(1);\n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] % 2 == 1) groups.push_back(1);\n            else groups.back()++;\n        }\n        for (int i = k; i < groups.size(); i++)\n            count += groups[i - k] * groups[i];\n        return count;\n    }\n```
[]