Skip to content
Onsite

Subarrays With Odd Endpoint Sum

MediumP3Coding

Count the subarrays of nums that have length greater than 1 and whose first element plus last element is odd. Subarrays are contiguous and are distinguished by their start and end indices.

Example 1

Input
nums = [1,2,3]
Output
2
Why
(1,2) and (2,3) have odd endpoint sums; (1,2,3) has 1 + 3 = 4.

Example 2

Input
nums = [1,3,5]
Output
0

Example 3

Input
nums = []
Output
0

Constraints

  • 0 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 10.