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 two elements ; Stores sum of all three subarrays ; Sum of left subarray ; Sum of middle subarray ; Sum of right subarray ; Check if sum of subarrays are equal ; Print the possible pair ; If no pair exists , print - 1 ; Driver code ; Given array ; Size of the array
def findSplit ( arr , N ) : NEW_LINE INDENT for l in range ( 1 , N - 3 , 1 ) : NEW_LINE INDENT for r in range ( l + 2 , N - 1 , 1 ) : NEW_LINE INDENT lsum = 0 NEW_LINE rsum = 0 NEW_LINE msum = 0 NEW_LINE for i in range ( 0 , l , 1 ) : NEW_LINE INDENT lsum += arr [ i ] NEW_LINE DEDENT for i in range ( l + 1 , r , 1 ) : NEW_LINE INDENT msum += arr [ i ] NEW_LINE DEDENT for i in range ( r + 1 , N , 1 ) : NEW_LINE INDENT rsum += arr [ i ] NEW_LINE DEDENT 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