Longest subarray with odd product | Function to return length of longest subarray with odd product ; If even element is encountered ; Update maximum ; Driver Code
function Maxlen ( arr , n ) { let ans = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) count = 0 ; else count ++ ; ans = Math . max ( ans , count ) ; } return ans ; } let arr = [ 1 , 7 , 2 ] ; let n = arr . length ; document . write ( Maxlen ( arr , n ) ) ;