Problems > Exactly K Odd Numbers > Editorial

Exactly K Odd Numbers — Solution & Editorial

Back to the Problem

Exactly K = (at most K) − (at most K−1), each a sliding window counting valid left endpoints per right endpoint.

Complexity: O(N)

Watch out: The count reaches ~5×109 — 64-bit.