Longest subarray with odd product | Function to return length of longest subarray with odd product ; If even element is encountered ; Update maximum ; Driver code
def Maxlen ( a , n ) : NEW_LINE INDENT ans = 0 NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if a [ i ] % 2 == 0 : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT ans = max ( ans , count ) NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 7 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( Maxlen ( arr , n ) ) NEW_LINE