Count subsequences having odd Bitwise OR values in an array | Function to count the subsequences having odd bitwise OR value ; Stores count of odd elements ; Stores count of even elements ; Traverse the array arr [ ] ; If element is odd ; Return the final answer ; Given array arr [ ]
function countSubsequences ( arr ) { let odd = 0 ; let even = 0 ; for ( let x of arr ) { if ( x & 1 ) odd ++ ; else even ++ ; } return ( ( 1 << odd ) - 1 ) * ( 1 << even ) ; } let arr = [ 2 , 4 , 1 ] ; document . write ( countSubsequences ( arr ) ) ;