5 kyu

Subarrays with an odd number of odd numbers

150 of 178ilash

Description:

Task

Implement a function which takes an array of nonnegative integers and returns the number of subarrays with an odd number of odd numbers. Note, a subarray is a contiguous subsequence.

Example

Consider an input:

[1, 2, 3, 4, 5]

The subarrays containing an odd number of odd numbers are the following:

[1, 2, 3, 4, 5], [2, 3, 4], [1, 2], [2, 3], [3, 4], [4, 5], [1], [3], [5]

The expected output is therefore 9.

Test suite

100 random tests, with small arrays, 5 <= size <= 200, testing the correctness of the solution.

10 performance tests, with arrays of size 200 000.

The expected output for an empty array is 0, otherwise the content of the arrays are always integers k such that 0 <= k <= 10000.

Expected time complexity is O(n)

Algorithms
Performance

More By Author:

Check out these other kata created by ilash

Stats:

CreatedSep 30, 2021
PublishedOct 1, 2021
Warriors Trained1866
Total Skips96
Total Code Submissions1166
Total Times Completed178
Python Completions150
C++ Completions33
Total Stars82
% of votes with a positive feedback rating94% of 34
Total "Very Satisfied" Votes31
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • ilash Avatar
  • 66  Avatar
  • cemsina Avatar
Ad