JAVA solution | Current problem transformed to Problem 560 | HashMap
Please Upvote !!! (\u25E0\u203F\u25E0)\nWe traverse the whole array and put 0 in place of even elements and 1 in place of odd elements. \nSo instead of finding 
#### *Please Upvote !!!* **(\u25E0\u203F\u25E0)**\nWe traverse the whole array and put 0 in place of even elements and 1 in place of odd elements. \nSo instead of finding k odd numbers, we now find subarrays whose sum will be equal to k (Because the odd numbers are all 1 and k odd numbers will give a sum of k now).\n\nThis takes us to the problem [**560. Subarray Sum Equals K**](https://leetcode.com/problems/subarray-sum-equals-k/).\n\nWe can put 0s and 1s in place of even and odd number by simply iterating through the array. \n```\nfor (int i = 0; i < nums.length; i++) {\n\tnums[i] = (nums[i] % 2 == 0) ? 0 : 1;\n}\n```\nBut that would take an extra O(n) time complexity. \n\nSo we won\'t do that. In Problem 560, we add ```nums[i]``` to ```sum``` at each iteration. So why not decide there itself whether to add 0 or 1 to sum!\n\nBelow is the solution, exactly similar to Problem 560.\n```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        int total = 0, sum = 0;\n        Map<Integer, Integer> map = new HashMap<>();\n        map.put(0, 1);\n\n        for (int i = 0; i < nums.length; i++) {\n            sum += (nums[i] % 2 == 0) ? 0 : 1;\n            int rem = sum - k;\n\n            if (map.containsKey(rem)) {\n                total += map.get(rem);\n            }\n\n            map.put(sum, map.getOrDefault(sum, 0) + 1);\n        }\n\n        return total;\n    }\n}\n\n// TC: O(n), SC: O(n)\n```
['Java']