Count Number of Nice Subarrays
Counting Subarrays and Fixed Window DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Count number of nice subarrays, Arrays, Subarray, Prefix Sum, Hash Map, Sliding Window, Two Pointers, Loops, Conditional Statements, Time Complexity, Space Complexity, sliding window, counting, subarray, prefix sum, hash map, Subarray/Substring Problems.
Problem Statement Given an array of positive integers nums and an integer k, return the number of "nice" subarrays. A "nice" subarray is defined as a contiguous subarray where the number of odd integers is exactly k. Input Specification The input consists of two parts: An array of integers, nums. An integer, k. Output Specification Return an integer representing the total count of nice subarrays. Constraints 1 <= nums.length <= 5 10^4 1 <= nums[i] <= 10^9 1 <= k <= nums.length Sample Test Case Input: Output: Explanation: The nice subarrays are [1,1,2,1] (contains 3 odd numbers: 1, 1, 1) and [1,2,1,1] (contains 3 odd numbers: 1, 1, 1).