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
< ? php function subsetBitwiseORk ( $ arr , $ n , $ k ) { $ v = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ( $ arr [ $ i ] $ k ) == $ k ) array_push ( $ v , $ arr [ $ i ] ) ; } $ ans = 0 ; for ( $ i = 0 ; $ i < count ( $ v ) ; $ i ++ ) $ ans |= $ v [ $ i ] ; if ( $ ans != $ k ) { echo ( " Subset ▁ does ▁ not ▁ exist STRNEWLINE " ) ; return ; } for ( $ i = 0 ; $ i < count ( $ v ) ; $ i ++ ) echo ( $ v [ $ i ] . " ▁ " ) ; } $ k = 3 ; $ arr = array ( 1 , 4 , 2 ) ; $ n = count ( $ arr ) ; subsetBitwiseORk ( $ arr , $ n , $ k ) ; ? >