human
Write me a code to count maximum non and the other steps required given the following:
Count maximum non | Function to count maximum number of non - overlapping subarrays with sum equals to the target.
Stores the final count.
Next subarray should start from index >= availIdx.
Tracks the prefix sum.
Map to store the prefix sum for respective indices.
Check if cur_sum - target is present in the array or not.
Update the index of current prefix sum.
Return the count of subarrays.
Driver Code.
Given array arr [ ].
Given sum target.
Function call"
Solution in Python:
assistant
#Here is code to count maximum non and the other steps required.
 def maximumSubarrays ( arr , N , target ) :
	ans = 0
	availIdx = - 1
	cur_sum = 0
	mp = { }
	mp [ 0 ] = - 1
	for i in range ( N ) :
		cur_sum += arr [ i ]
		if ( ( cur_sum - target ) in mp and mp [ cur_sum - target ] >= availIdx ) :
			ans += 1
			availIdx = i
		mp [ cur_sum ] = i
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , - 1 , 4 , 3 , 6 , 4 , 5 , 1 ]
	N = len ( arr )
	target = 6
	print ( maximumSubarrays ( arr , N , target ) )