human
Longest subarray having count of 1 s one more than count of 0 s | function to find the length of longest subarray having count of 1 ' s ▁ one ▁ more ▁ than ▁ count ▁ of ▁ 0' s.
unordered_map ' um ' implemented as hash table.
traverse the given array.
consider '0' as '-1  .
when subarray starts form index '0  .
make an entry for ' sum ' if it is not present in 'um  .
check if ' sum - 1' is present in ' um ' or not.
update maxLength.
required maximum length.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to longest subarray having count of 1 s one more than count of 0 s and the other steps required.
 def lenOfLongSubarr ( arr , n ) :
	um = { i : 0 for i in range ( 10 ) }
	sum = 0
	maxLen = 0
	for i in range ( n ) :
		if arr [ i ] == 0 :
			sum += - 1
		else :
			sum += 1
		if ( sum == 1 ) :
			maxLen = i + 1
		elif ( sum not in um ) :
			um [ sum ] = i
		if ( ( sum - 1 ) in um ) :
			if ( maxLen < ( i - um [ sum - 1 ] ) ) :
				maxLen = i - um [ sum - 1 ]
	return maxLen
if __name__ == ' _ _ main _ _ ' :
	arr = [ 0 , 1 , 1 , 0 , 0 , 1 ]
	n = len ( arr )
	print ( " Length ▁ = " , lenOfLongSubarr ( arr , n ) )