human
What is a code to longest sub and the other steps required given the following:
Longest sub | Function to find the starting and the ending index of the sub - array with equal number of alphabets and numeric digits.
If its an alphabet.
Else its a number.
Pick a starting poas i.
Consider all sub - arrays starting from i.
If this is a 0 sum sub - array then compare it with maximum size sub - array calculated so far.
If no valid sub - array found.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to longest sub and the other steps required.
 def findSubArray ( arr , n ) :
	sum = 0
	maxsize = - 1
	startindex = 0
	for i in range ( n ) :
		if ( arr [ i ] . isalpha ( ) ) :
			arr [ i ] = 0
		else :
			arr [ i ] = 1
	for i in range ( n - 1 ) :
		if arr [ i ] == '1' :
			sum = 1
		else :
			sum = - 1
		for j in range ( i + 1 , n ) :
			if arr [ j ] == 0 :
				sum -= 1
			else :
				sum += 1
			if ( sum == 0 and maxsize < j - i + 1 ) :
				maxsize = j - i + 1
				startindex = i
	if ( maxsize == - 1 ) :
		print ( maxsize , end = " ▁ " )
	else :
		print ( startindex , ( startindex + maxsize - 1 ) )
arr = [ ' A ' , ' B ' , ' X ' , '4' , '6' , ' X ' , ' a ' ]
size = len ( arr )
findSubArray ( arr , size )