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 ; Stores prefix sum array ; Traverse the array ; Stores sums of all three subarrays ; Sum of left subarray ; Sum of middle subarray ; Sum of right subarray ; Check if sum of subarrays are equal ; Prthe possible pair ; If no such pair exists , pr - 1 ; Driver Code ; Given array ; Size of the array
def findSplit ( arr , N ) : NEW_LINE INDENT sum = [ i for i in arr ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT sum [ i ] += sum [ i - 1 ] NEW_LINE DEDENT for l in range ( 1 , N - 3 ) : NEW_LINE INDENT for r in range ( l + 2 , N - 1 ) : NEW_LINE INDENT lsum , rsum , msum = 0 , 0 , 0 NEW_LINE lsum = sum [ l - 1 ] NEW_LINE msum = sum [ r - 1 ] - sum [ l ] NEW_LINE rsum = sum [ N - 1 ] - sum [ r ] NEW_LINE if ( lsum == rsum and rsum == msum ) : NEW_LINE INDENT print ( l , r ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE findSplit ( arr , N ) NEW_LINE DEDENT