Editorial solution... #Perfectly Beats all 100%
\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -
\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n    def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        curr_sum = 0\n        subarrays = 0\n        prefix_sum = {curr_sum: 1}\n\n        for i in range(len(nums)):\n            curr_sum += nums[i] % 2\n            # Find subarrays with sum k ending at i\n            if curr_sum - k in prefix_sum:\n                subarrays = subarrays + prefix_sum[curr_sum - k]\n            # Increment the current prefix sum in hashmap\n            prefix_sum[curr_sum] = prefix_sum.get(curr_sum, 0) + 1\n\n        return subarrays\n```
['Array', 'Hash Table', 'Math', 'C', 'Sliding Window', 'Python', 'C++', 'Java', 'Python3']