Count of sub | Function that returns the count of sub - arrays with odd product ; Initialize the count variable ; Initialize variable to store the last index with even number ; Initialize variable to store count of continuous odd numbers ; Loop through the array ; Check if the number is even or not ; Calculate count of continuous odd numbers ; Increase the count of sub - arrays with odd product ; Store the index of last even number ; N considered as index of even number ; Driver Code ; Function call
function countSubArrayWithOddProduct ( A , N ) { var count = 0 ; var last = - 1 ; var K = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) { K = ( i - last - 1 ) ; count += ( K * ( K + 1 ) / 2 ) ; last = i ; } } K = ( N - last - 1 ) ; count += ( K * ( K + 1 ) / 2 ) ; return count ; } var arr = [ 12 , 15 , 7 , 3 , 25 , 6 , 2 , 1 , 1 , 7 ] ; var n = arr . length ; document . write ( countSubArrayWithOddProduct ( arr , n ) ) ;