I went with the prefix count plus hashmap approach, tracking how many times each odd-number count had appeared and checking the difference.
Use a sliding window (two pointers) to count subarrays with at most k odd numbers, then subtract the count for at most k-1 odd numbers. This yields the number of subarrays with exactly k odd numbers in O(n) time and O(1) space. Alternatively, use prefix sums of odd counts with a hash map to count pairs with difference k.
Pro tip: Clarify that the array can contain any integers, but only parity matters; also mention edge cases like k=0 or k greater than total odd numbers. This shows attention to detail and robustness.
Restate the problem: count contiguous subarrays with exactly k odd numbers. Clarify that only the parity of elements matters, and that k can be zero or larger than the total odd count.
Decide between sliding window (at most k minus at most k-1) or prefix sum with hash map. Explain the trade-offs: sliding window is O(n) time and O(1) space, while prefix sum uses O(n) space but is also O(n) time.
For sliding window: write a helper function to count subarrays with at most k odd numbers. For prefix sum: iterate through the array, maintain a running count of odds, and use a hash map to store frequencies of previous counts.
Consider k=0 (subarrays with no odd numbers), k > total odds (answer 0), empty array, and large inputs. Ensure the solution handles these correctly.
State time and space complexity. Walk through a small example to verify correctness, and mention potential pitfalls like integer overflow or off-by-one errors.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.