Count Number of Nice Subarrays Problem

Count Number of Nice Subarrays Problem — ExecCode Easy DSA Practice

Solve the Count Number of Nice Subarrays problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A subarray is called nice when it contains exactly k odd numbers. Given an integer array nums and an integer k, return the total count of nice subarrays.

Examples

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

Constraints

1 ≤ nums.length ≤ 5×10⁴ 1 ≤ nums[i] ≤ 10⁵ 1 ≤ k ≤ nums.length

Practice Count Number of Nice Subarrays free on ExecCode. Browse DSA problems, topic map, and placement guides.