Find a partition point in array to maximize its xor sum | Function to calculate Prefix Xor array ; Calculating prefix xor ; Function to find partition point in array to maximize xor sum ; To store prefix xor ; Compute the prefix xor ; To store sum and index ; Calculate the maximum sum that can be obtained splitting the array at some index i ; PrefixXor [ i ] = Xor of all arr elements till i ' th ▁ index ▁ PrefixXor [ n - 1 ] ▁ ▁ ^ ▁ PrefixXor [ i ] ▁ = ▁ Xor ▁ of ▁ all ▁ elements ▁ ▁ from ▁ i + 1' th index to n - 1 'th index ; Return the index ; Driver code ; Function call
def ComputePrefixXor ( arr , PrefixXor , n ) : NEW_LINE INDENT PrefixXor [ 0 ] = arr [ 0 ] ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; NEW_LINE DEDENT DEDENT def Xor_Sum ( arr , n ) : NEW_LINE INDENT PrefixXor = [ 0 ] * n ; NEW_LINE ComputePrefixXor ( arr , PrefixXor , n ) ; NEW_LINE sum , index = 0 , 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) : NEW_LINE INDENT sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; NEW_LINE index = i ; NEW_LINE DEDENT DEDENT return index + 1 ; NEW_LINE DEDENT arr = [ 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( Xor_Sum ( arr , n ) ) ; NEW_LINE