JAVA Solution Explained in HINDI(2 Approaches)
https://youtu.be/xufUS2MRAZw\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/xufUS2MRAZw\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 500\nCurrent Subscriber:- 453\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private int numSubarraysLessThanOrEqualToGoal(int[] nums, int goal) {\n        int i = 0, j = 0, n = nums.length, count = 0, ans = 0;\n\n        while (j < n) {\n            if (nums[j] % 2 == 1) count++;\n            while (i <= j && count > goal) {\n                if (nums[i] % 2 == 1) count--;\n                i++;\n            }\n            ans += j - i + 1;\n            j++;\n        }\n        return ans;\n    }\n\n    public int numberOfSubarrays(int[] nums, int k) {\n        return numSubarraysLessThanOrEqualToGoal(nums, k) - \n               numSubarraysLessThanOrEqualToGoal(nums, k - 1);\n    }\n}\n```\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        int n = nums.length;\n        int ans = 0;\n        int prefSum = 0;\n        Map<Integer, Integer> freq = new HashMap<>();\n        freq.put(0, 1);\n\n        for (int i = 0; i < n; i++) {\n            prefSum += (nums[i] % 2 == 1) ? 1 : 0;\n            ans += freq.getOrDefault(prefSum - k, 0);\n            freq.put(prefSum, freq.getOrDefault(prefSum, 0) + 1);\n        }\n        return ans;\n    }\n}\n```
['Java']