Number of sub arrays with odd sum | Python 3 code to find count of sub - arrays with odd sum ; Find sum of all subarrays and increment result if sum is odd ; Driver code
def countOddSum ( ar , n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT val = 0 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT val = val + ar [ j ] NEW_LINE if ( val % 2 != 0 ) : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT return ( result ) NEW_LINE DEDENT ar = [ 5 , 4 , 4 , 5 , 1 , 3 ] NEW_LINE print ( " The ▁ Number ▁ of ▁ Subarrays " , " with ▁ odd " , end = " " ) NEW_LINE print ( " ▁ sum ▁ is ▁ " + str ( countOddSum ( ar , 6 ) ) ) NEW_LINE