772. Max Odd Numbers in K Window
Given an integer array nums and an integer k, return the maximum number of odd numbers present in a subarray of size k within nums.
Example 1:
Input: nums = [2, 3, 3, 2, 9, 2, 5], k = 4
Output: 3
Explanation: The subarray [3, 3, 2, 9] is the optimal choice with the maximum odd numbers possible = 3.
Example 2:
Input: nums = [9, 2, 2, 5, 8, 6], k = 3
Output: 1
Explanation: [9, 2, 2] is one of the optimal subarrays, [2, 5, 8] is also valid.
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 105
- -104 <= nums[i] <= 104
- 1 <= k <= n