c++ O(1) space 97%faster 100 % space efficient
\nclass Solution {\npublic:\n    Solution()\n    {\n        ios_base::sync_with_stdio(0);\n        cin.tie(0);\n        cout.tie(0);\n    }\n    int func(vector
```\nclass Solution {\npublic:\n    Solution()\n    {\n        ios_base::sync_with_stdio(0);\n        cin.tie(0);\n        cout.tie(0);\n    }\n    int func(vector<int> &nums,int k)\n    {\n        int j=0;\n        int cnt=0;\n        int n=nums.size();\n        for(int i=0;i<n;i++)\n        {\n            if(nums[i]%2)k--;\n            while(k<0)\n            {\n                if(nums[j]%2)k++;\n                j++;\n            }\n            cnt+=i-j+1;\n        }\n        return cnt;\n    }\n    int numberOfSubarrays(vector<int>& nums, int k) {\n\t\t\treturn func(nums,k)-func(nums,k-1);//func calculate for atmost case. exact k=atmost k -atmost k-1;\n    }\n};\n```
['C', 'Sliding Window']