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 . ; displaying the values
using System ; using System . Collections . Generic ; class CP { public static void Main ( String [ ] args ) { int [ ] A = { 11 , 15 , 7 , 19 } ; int N = A . Length ; HashSet < int > set1 = new HashSet < int > ( ) ; int i , j , res ; for ( i = 0 ; i < N ; ++ i ) { for ( j = i , res = int . MaxValue ; j < N ; ++ j ) { res &= A [ j ] ; set1 . Add ( res ) ; } } foreach ( int m in set1 ) { Console . Write ( m + " ▁ " ) ; } } }