Longest subarray with all elements same | Function to find largest sub array with all equal elements . ; Traverse the array ; If element is same as previous increment temp value ; Return the required answer ; Driver code ; Function call
def subarray ( arr , n ) : NEW_LINE INDENT ans , temp = 1 , 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if arr [ i ] == arr [ i - 1 ] : NEW_LINE INDENT temp = temp + 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max ( ans , temp ) NEW_LINE temp = 1 NEW_LINE DEDENT DEDENT ans = max ( ans , temp ) NEW_LINE return ans NEW_LINE DEDENT arr = [ 2 , 2 , 1 , 1 , 2 , 2 , 2 , 3 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( subarray ( arr , n ) ) NEW_LINE