Number of times an array can be partitioned repetitively into two subarrays with equal sum | Recursion Function to calculate the possible splitting ; If there are less than two elements , we cannot partition the sub - array . ; Iterate from the start to end - 1. ; Recursive call to the left and the right sub - array . ; If there is no such partition , then return 0 ; Function to find the total splitting ; Prefix array to store the prefix - sum using 1 based indexing ; Store the prefix - sum ; Function Call to count the number of splitting ; Given array ; Function call
def splitArray ( start , end , arr , prefix_sum ) : NEW_LINE INDENT if ( start >= end ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT for k in range ( start , end ) : NEW_LINE INDENT if ( ( prefix_sum [ k ] - prefix_sum [ start - 1 ] ) == ( prefix_sum [ end ] - prefix_sum [ k ] ) ) : NEW_LINE INDENT return ( 1 + splitArray ( start , k , arr , prefix_sum ) + splitArray ( k + 1 , end , arr , prefix_sum ) ) NEW_LINE DEDENT DEDENT return 0 NEW_LINE DEDENT def solve ( arr , n ) : NEW_LINE INDENT prefix_sum = [ 0 ] * ( n + 1 ) NEW_LINE prefix_sum [ 0 ] = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT prefix_sum [ i ] = ( prefix_sum [ i - 1 ] + arr [ i - 1 ] ) NEW_LINE DEDENT print ( splitArray ( 1 , n , arr , prefix_sum ) ) NEW_LINE DEDENT arr = [ 12 , 3 , 3 , 0 , 3 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE solve ( arr , N ) NEW_LINE