Sum of Bitwise And of all pairs in a given array | Returns value of " arr [ 0 ] ▁ & ▁ arr [ 1 ] ▁ + ▁ ▁ arr [ 0 ] ▁ & ▁ arr [ 2 ] ▁ + ▁ . . . ▁ arr [ i ] ▁ & ▁ arr [ j ] ▁ + ▁ ▁ . . . . . ▁ arr [ n - 2 ] ▁ & ▁ arr [ n - 1 ] " ; Consider all pairs ( arr [ i ] , arr [ j ) such that i < j ; Driver Code
function pairAndSum ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) ans += arr [ i ] & arr [ j ] ; return ans ; } let arr = [ 5 , 10 , 15 ] ; let n = arr . length ; document . write ( pairAndSum ( arr , n ) ) ;