Count ways to make Bitwise XOR of odd and even indexed elements equal by removing an array element | Function to count ways to make Bitwise XOR of odd and even indexed elements equal by removing an array element ; Stores xor of odd and even indexed elements from the end ; Stores xor of odd and even indexed elements from the start ; Stores the required count ; Traverse the array in reverse ; If i is odd ; If i is even ; Traverse the array ; If i is odd ; If i is even ; Removing arr [ i ] , post_even stores XOR of odd indexed elements ; Removing arr [ i ] , post_odd stores XOR of even indexed elements ; Check if they are equal ; If i is odd , xor it with curr_odd ; If i is even , xor it with curr_even ; Finally print res ; Drivers Code ; Given array ; Given size ; Function call
def Remove_one_element ( arr , n ) : NEW_LINE INDENT post_odd = 0 NEW_LINE post_even = 0 NEW_LINE curr_odd = 0 NEW_LINE curr_even = 0 NEW_LINE res = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( i % 2 ) : NEW_LINE INDENT post_odd ^= arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT post_even ^= arr [ i ] NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( i % 2 ) : NEW_LINE INDENT post_odd ^= arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT post_even ^= arr [ i ] NEW_LINE DEDENT X = curr_odd ^ post_even NEW_LINE Y = curr_even ^ post_odd NEW_LINE if ( X == Y ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT if ( i % 2 ) : NEW_LINE INDENT curr_odd ^= arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT curr_even ^= arr [ i ] NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 0 , 1 , 0 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE Remove_one_element ( arr , N ) NEW_LINE DEDENT