Count Number of Nice Subarray
\n\n\n\n\n\n\nDiscuss\n\n1. In this problem , First we will change the odd digit from 1 and even with zero in given array.\n2. calculating the sum from start to
\n\n\n\n\n![image](https://assets.leetcode.com/users/images/edf56675-d477-426e-ae38-2c78ff496b20_1640928608.742415.png)\n\n**Discuss**\n\n1. In this problem , First we will change the odd digit from 1 and even with zero in given array.\n2. calculating the sum from start to end index with comparison k value\ni.e. sum - k == 0\n3. then we find subarray whose array has k odd value and stored in map. after this check again for another subarray because if we got odd value equal to the given k value then we got the subarray which has k odd value.\n\n**Note : this problem basically similar to the find subarray whose sum is equal to 0**\n\nclass Solution {\n\n    public int numberOfSubarrays(int[] nums, int k) {          \n        Map<Integer, Integer> mp = new HashMap<>();\n        int res = 0;\n        int sum = 0;\n        for (int j = 0; j < nums.length; j++) {\n            sum += nums[j] % 2;\n            if (sum - k == 0) {\n                res++;\n            }\n            if (mp.containsKey(sum - k)) {\n                res += mp.get(sum - k);\n            }\n            mp.put(sum, mp.getOrDefault(sum, 0) + 1);\n        }\n        return res;\n    }\n}\n**Please help to UPVOTE if this post is useful for you.\nIf you have any questions, feel free to comment below.\nHAPPY CODING :)\nLOVE CODING :)**
['Sliding Window']