Subarrays with at Most One Odd Number

Problem Given an integer array, return every contiguous subarray containing at most one odd number.

Input / Output

  • Input: int array nums.
  • Output: all qualifying subarrays (or their count — clarify which).

Constraints

  • Output can be O(n^2) in size when listing; the counting variant should run O(n).

Example

  • nums = {2,3,5,6,8} → {2}, {2,3}, {3}, {5}, {5,6}, {5,6,8}, {6}, {6,8}, {8}.
asked …
LeaderboardSalaryAccount
Subarrays with at Most One Odd Number · 2dbi