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
Similar Kata:
Stats:
Created | Sep 30, 2021 |
Published | Oct 1, 2021 |
Warriors Trained | 1866 |
Total Skips | 96 |
Total Code Submissions | 1166 |
Total Times Completed | 178 |
Python Completions | 150 |
C++ Completions | 33 |
Total Stars | 82 |
% of votes with a positive feedback rating | 94% of 34 |
Total "Very Satisfied" Votes | 31 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |