Length of longest sub | Function to find maximum distance between unequal elements ; Calculate maxMean ; Iterate over array and calculate largest subarray with all elements greater or equal to maxMean ; Driver code
def longestSubarray ( arr , n ) : NEW_LINE INDENT maxMean = 0 ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT maxMean = max ( maxMean , ( arr [ i ] + arr [ i - 1 ] ) // 2 ) ; NEW_LINE DEDENT ans = 0 ; NEW_LINE subarrayLength = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] >= maxMean ) : NEW_LINE INDENT subarrayLength += 1 ; NEW_LINE ans = max ( ans , subarrayLength ) ; NEW_LINE DEDENT else : NEW_LINE INDENT subarrayLength = 0 ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT arr = [ 4 , 3 , 3 , 2 , 1 , 4 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( longestSubarray ( arr , n ) ) ; NEW_LINE