FunctionRacerProblemsRace

Stretches With K Odd Values

MediumHash mapsPython, JavaScript, TypeScript, Java, C++

Count the contiguous, non-empty stretches of nums that contain exactly k odd numbers. Stretches at different positions count separately even when they hold the same values.

Return the count. With k = 0, count the stretches made of even numbers only.

Example 1

nums [1,1,2,1,1]
k 3
returns 2

The stretches with exactly three odd numbers are 1, 1, 2, 1 and 1, 2, 1, 1.

Example 2

nums [2,4,6]
k 1
returns 0

There is no odd number at all, so no stretch has one.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems