Longest Sub | Function to return the max length of the sub - array that have the maximum average ( average value of the elements ) ; Finding the maximum value ; If consecutive maximum found ; Find the max length of consecutive max ; Driver code
def maxLenSubArr ( a , n ) : NEW_LINE INDENT cm , Max = 1 , 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if a [ i ] > Max : NEW_LINE INDENT Max = a [ i ] NEW_LINE DEDENT DEDENT i = 0 NEW_LINE while i < n - 1 : NEW_LINE INDENT count = 1 NEW_LINE if a [ i ] == a [ i + 1 ] and a [ i ] == Max : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if a [ j ] == Max : NEW_LINE INDENT count += 1 NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if count > cm : NEW_LINE INDENT cm = count NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return cm NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 6 , 1 , 6 , 6 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxLenSubArr ( arr , n ) ) NEW_LINE DEDENT