Numbers that are bitwise AND of at least one non | Java implementation of the approach ; Set to store all possible AND values . ; Starting index of the sub - array . ; Ending index of the sub - array . ; AND value is added to the set . ; The set contains all possible AND values .
import java . util . HashSet ; class CP { public static void main ( String [ ] args ) { int [ ] A = { 11 , 15 , 7 , 19 } ; int N = A . length ; HashSet < Integer > set = new HashSet < > ( ) ; int i , j , res ; for ( i = 0 ; i < N ; ++ i ) for ( j = i , res = Integer . MAX_VALUE ; j < N ; ++ j ) { res &= A [ j ] ; set . add ( res ) ; } System . out . println ( set ) ; } }