Count subarrays having even Bitwise XOR | Function to count the number of subarrays having even Bitwise XOR ; Store the required result ; Generate subarrays with arr [ i ] as the first element ; Store XOR of current subarray ; Generate subarrays with arr [ j ] as the last element ; Calculate Bitwise XOR of the current subarray ; If XOR is even , increase ans by 1 ; Prthe result ; Driver Code ; Given array ; Stores the size of the array ; Function Call
def evenXorSubarray ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT XOR = 0 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT XOR = XOR ^ arr [ j ] NEW_LINE if ( ( XOR & 1 ) == 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE evenXorSubarray ( arr , N ) NEW_LINE DEDENT