Subarrays with k odds

Write codeMedium25 min

Your task

Given an integer array a and an integer k, return the number of contiguous subarrays that contain exactly k odd numbers. The array may have length 1; k is non-negative.

Examples

count_nice_subarrays(a: list[int], k: int) -> int
Example 1
Inputcount_nice_subarrays([1, 1, 2, 1, 1], 3)
Output2