Maximum subset with bitwise OR equal to k | function to find the maximum subset with bitwise OR equal to k ; If the bitwise OR of k and element is equal to k , then include that element in the subset ; Store the bitwise OR of elements in v ; If ans is not equal to k , subset doesn 't exist ; Driver Code
function subsetBitwiseORk ( arr , n , k ) { var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] k ) == k ) v . push ( arr [ i ] ) ; } var ans = 0 ; for ( var i = 0 ; i < v . length ; i ++ ) ans |= v [ i ] ; if ( ans != k ) { document . write ( " " ) ; return ; } for ( var i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + ' ' ) ; } var k = 3 ; var arr = [ 1 , 4 , 2 ] ; var n = arr . length ; subsetBitwiseORk ( arr , n , k ) ;