human
Number of sub arrays with odd sum | Function to find number of subarrays with odd sum.
' odd ' stores number of odd numbers upto ith index ' c _ odd ' stores number of odd sum subarrays starting at ith index ' Result ' stores the number of odd sum subarrays.
First find number of odd sum subarrays starting at 0 th index.
Find number of odd sum subarrays starting at ith index add to result.
Driver code"
Solution in Python:
assistant
#Here is code to number of sub arrays with odd sum and the other steps required.
 def countOddSum ( a , n ) :
	c_odd = 0 ;
	result = 0 ;
	odd = False ;
	for i in range ( n ) :
		if ( a [ i ] % 2 == 1 ) :
			if ( odd == True ) :
				odd = False ;
			else :
				odd = True ;
		if ( odd ) :
			c_odd += 1 ;
	for i in range ( n ) :
		result += c_odd ;
		if ( a [ i ] % 2 == 1 ) :
			c_odd = ( n - i - c_odd ) ;
	return result ;
if __name__ == ' _ _ main _ _ ' :
	ar = [ 5 , 4 , 4 , 5 , 1 , 3 ] ;
	n = len ( ar ) ;
	print ( " The ▁ Number ▁ of ▁ Subarrays " + " with ▁ odd ▁ sum ▁ is ▁ " , countOddSum ( ar , n ) ) ;