human
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"
How can the above be solved in Python?
assistant
#Here is code to longest subarray with all elements same and the other steps required.
 def subarray ( arr , n ) :
	ans , temp = 1 , 1
	for i in range ( 1 , n ) :
		if arr [ i ] == arr [ i - 1 ] :
			temp = temp + 1
		else :
			ans = max ( ans , temp )
			temp = 1
	ans = max ( ans , temp )
	return ans
arr = [ 2 , 2 , 1 , 1 , 2 , 2 , 2 , 3 , 3 ]
n = len ( arr )
print ( subarray ( arr , n ) )