text: Sum of squares of all Subsets of given Array | Javascript implementation of the approach ; Function to return ( 2 ^ P % mod ) ; Function to return the sum of squares of subsets ; Sqauaring the elements and adding it to ans ; Driver code
code: const mod = 1000000000 + 7 ; function power ( p ) { let res = 1 ; for ( let i = 1 ; i <= p ; ++ i ) { res *= 2 ; res %= mod ; } return res % mod ; } function subset_square_sum ( A ) { let n = A . length ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans += ( A [ i ] * A [ i ] ) % mod ; ans %= mod ; } return ( ans * power ( n - 1 ) ) % mod ; } let A = [ 3 , 7 ] ; document . write ( subset_square_sum ( A ) ) ;