Skip to content

Practice Count Number of Nice Subarrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1248
LeetCode Problem

Count Number of Nice Subarrays

Problem Statement

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.

Source: Count Number of Nice Subarrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,1,2,1,1], k = 3
Output
2

# Example 2

Input
nums = [2,4,6], k = 1
Output
0

# Example 3

Input
nums = [2,2,2,1,2,2,1,2,2,2], k = 2
Output
16

Constraints

1 <= nums.length <= 50000
1 <= nums[i] <= 10^5
1 <= k <= nums.length

Related LeetCode Problems

Practice more problems similar to Count Number of Nice Subarrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.