human
Largest subarray with frequency of all elements same | Function to find maximum subarray size.
Generating all subarray i -> starting index j -> end index.
Map 1 to hash frequency of all elements in subarray.
Map 2 to hash frequency of all frequencies of elements.
Finding previous frequency of arr [ j ] in map 1.
Increasing frequency of arr [ j ] by 1.
Check if previous frequency is present in map 2.
Delete previous frequency if hash is equal to 1.
Decrement the hash of previous frequency.
Incrementing hash of new frequency in map 2.
Check if map2 size is 1 and updating answer.
Return the maximum size of subarray.
Given array arr [ ].
Function Call"
How can the above be solved in Python?
assistant
#Here is code to largest subarray with frequency of all elements same and the other steps required.
 def max_subarray_size ( N , arr ) :
	ans = 0
	for i in range ( N ) :
		map1 = { }
		map2 = { }
		for j in range ( i , N ) :
			if ( arr [ j ] not in map1 ) :
				ele_count = 0
			else :
				ele_count = map1 [ arr [ j ] ]
			if arr [ j ] in map1 :
				map1 [ arr [ j ] ] += 1
			else :
				map1 [ arr [ j ] ] = 1
			if ( ele_count in map2 ) :
				if ( map2 [ ele_count ] == 1 ) :
					del map2 [ ele_count ]
				else :
					map2 [ ele_count ] -= 1
			if ele_count + 1 in map2 :
				map2 [ ele_count + 1 ] += 1
			else :
				map2 [ ele_count + 1 ] = 1
			if ( len ( map2 ) == 1 ) :
				ans = max ( ans , j - i + 1 )
	return ans
arr = [ 1 , 2 , 2 , 5 , 6 , 5 , 6 ]
N = len ( arr )
print ( max_subarray_size ( N , arr ) )