Numbers that are bitwise AND of at least one non | C ++ 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 .
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int A [ ] = { 11 , 15 , 7 , 19 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; unordered_set < int > s ; int i , j , res ; for ( i = 0 ; i < N ; ++ i ) for ( j = i , res = INT_MAX ; j < N ; ++ j ) { res &= A [ j ] ; s . insert ( res ) ; } for ( int i : s ) cout << i << " ▁ " ; return 0 ; }