human
Can you provide a code to print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays and the other steps required given the following:
Print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays | Function to check if array can be split into three equal sum subarrays by removing a pair.
Two pointers l and r.
Stores prefix sum array.
Traverse the array.
Two pointer approach.
Sum of left subarray.
Sum of middle subarray.
Sum of right subarray.
Print split indices if sum is equal.
Move left pointer if lsum < rsum.
Move right pointer if rsum > lsum.
Move both pointers if lsum = rsum but they are not equal to msum.
If no possible pair exists , print - 1.
Driver Code.
Given array.
Size of the array"
How can the above be solved in Python?
assistant
#Here is code to print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays and the other steps required.
 def findSplit ( arr , N ) :
	l = 1 ; r = N - 2 ;
	sum = [ 0 ] * N ;
	sum [ 0 ] = arr [ 0 ] ;
	for i in range ( 1 , N ) :
		sum [ i ] = sum [ i - 1 ] + arr [ i ] ;
	while ( l < r ) :
		lsum = sum [ l - 1 ] ;
		msum = sum [ r - 1 ] - sum [ l ] ;
		rsum = sum [ N - 1 ] - sum [ r ] ;
		if ( lsum == msum and msum == rsum ) :
			print ( l , r ) ;
			return ;
		if ( lsum < rsum ) :
			l += 1 ;
		elif ( lsum > rsum ) :
			r -= 1 ;
		else :
			l += 1 ;
			r -= 1 ;
	print ( - 1 ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ] ;
	N = len ( arr ) ;
	findSplit ( arr , N ) ;