15. Count Number of Nice Subarrays
Given an array of integers nums
and an integer k
. A continuous subarray is called nice if there are k
odd numbers on it.
Return the number of nice sub-arrays.
Example 1:
Example 2:
Example 3:
Solution: (Sliding Window)
Approach: We find the position of odd number We then calculate the maximum expansion possible on both sides Number of subarrays = number of element on left * number of element on right
Time Complexity: O(n) Space Complexity: O(n)
Last updated