← 返回 bytedance 的题目列表Count Number of Nice Subarrays
类型:online_judge
Problem: Count Number of Nice Subarrays
Given an integer array nums and an integer k.
A continuous subarray is called nice if it contains exactly k odd numbers.
Return the number of nice subarrays.
Input Format
The first line contains two integers n and k, where n is the length of the array and k is the target number of odd numbers.
The second line contains n integers representing nums.
Output Format
Print one integer: the number of continuous subarrays containing exactly k odd numbers.
Constraints
1 <= n <= 50000
1 <= nums[i] <= 100000
1 <= k <= n
Example
Input:
5 3
1 1 2 1 1
Output:
2
Explanation: The nice subarrays are [1,1,2,1] and [1,2,1,1].
Example
Input
5 3
1 1 2 1 1
Output
2