Count subarrays having odd Bitwise XOR | Function to count the number of subarrays of the given array having odd Bitwise XOR ; Stores number of odd numbers upto i - th index ; Stores number of required subarrays starting from i - th index ; Store the required result ; Find the number of subarrays having odd Bitwise XOR values starting at 0 - th index ; Check if current element is odd ; If the current value of odd is not zero , increment c_odd by 1 ; Find the number of subarrays having odd bitwise XOR value starting at ith index and add to result ; Add c_odd to result ; Print the result ; Driver Code ; Given array ; Stores the size of the array
def oddXorSubarray ( a , n ) : NEW_LINE INDENT odd = 0 NEW_LINE c_odd = 0 NEW_LINE result = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] & 1 ) : NEW_LINE INDENT odd = not odd NEW_LINE DEDENT if ( odd ) : NEW_LINE INDENT c_odd += 1 NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT result += c_odd NEW_LINE if ( a [ i ] & 1 ) : NEW_LINE INDENT c_odd = ( n - i - c_odd ) NEW_LINE DEDENT DEDENT print ( result ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 4 , 7 , 9 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE oddXorSubarray ( arr , N ) NEW_LINE DEDENT