Count ways to split array into three non | Function to count ways to split array into three subarrays with equal Bitwise XOR ; Stores the XOR value of arr [ ] ; Update the value of arr_xor ; Stores the XOR value of prefix and suffix array respectively ; Stores the ending points of all the required prefix arrays ; Stores the count of suffix arrays whose XOR value is equal to the total XOR value at each index ; Find all prefix arrays with XOR value equal to arr_xor ; Update pref_xor ; Fill the values of suff_inds [ ] ; Update suff_xor ; Update suff_inds [ i ] ; Stores the total number of ways ; Count total number of ways ; Return the final count ; Driver Code ; Given Input ; Function Call
def countWays ( arr , N ) : NEW_LINE INDENT arr_xor = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT arr_xor ^= arr [ i ] NEW_LINE DEDENT pref_xor , suff_xor = 0 , 0 NEW_LINE pref_ind = [ ] NEW_LINE suff_inds = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT pref_xor ^= arr [ i ] NEW_LINE if ( pref_xor == arr_xor ) : NEW_LINE INDENT pref_ind . append ( i ) NEW_LINE DEDENT DEDENT for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT suff_xor ^= arr [ i ] NEW_LINE suff_inds [ i ] += suff_inds [ i + 1 ] NEW_LINE if ( suff_xor == arr_xor ) : NEW_LINE INDENT suff_inds [ i ] += 1 NEW_LINE DEDENT DEDENT tot_ways = 0 NEW_LINE for idx in pref_ind : NEW_LINE INDENT if ( idx < N - 1 ) : NEW_LINE INDENT tot_ways += suff_inds [ idx + 2 ] NEW_LINE DEDENT DEDENT return tot_ways NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 7 , 0 , 5 , 2 , 7 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countWays ( arr , N ) ) NEW_LINE DEDENT