Count subsequences having odd Bitwise OR values in an array | Java implementation for the above approach ; 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 ; Driver Code ; Given array arr [ ]
import java . io . * ; class GFG { static int countSubsequences ( int arr [ ] ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; else even ++ ; } return ( ( 1 << odd ) - 1 ) * ( 1 << even ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 1 } ; System . out . println ( countSubsequences ( arr ) ) ; } }