Count subarrays having even Bitwise OR | Function to count the number of subarrays having even Bitwise OR ; Store number of subarrays having even bitwise OR ; Store the length of the current subarray having even numbers ; Traverse the array ; If the element is even ; Increment size of the current continuous sequence of even array elements ; If arr [ i ] is odd ; If length is non zero ; Adding contribution of subarrays consisting only of even numbers ; Make length of subarray as 0 ; Add contribution of previous subarray ; Return total count of subarrays ; Driver Code ; Function Call
def bitOr ( arr , N ) : NEW_LINE INDENT count = 0 NEW_LINE length = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT length += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( length != 0 ) : NEW_LINE INDENT count += ( ( length ) * ( length + 1 ) ) // 2 NEW_LINE DEDENT length = 0 NEW_LINE DEDENT DEDENT count += ( ( length ) * ( length + 1 ) ) // 2 NEW_LINE return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 5 , 4 , 2 , 6 ] NEW_LINE N = len ( arr ) NEW_LINE print ( bitOr ( arr , N ) ) NEW_LINE DEDENT