Skip to content

Latest commit

 

History

History
30 lines (16 loc) · 540 Bytes

Sum of bit difference.md

File metadata and controls

30 lines (16 loc) · 540 Bytes
	
	long long sumBitDifferences(int arr[], int n) {
	    long count = 0;

        for (int i = 0; i < 32; i++) { 

            int countSet = 0;

            for (int j=0;j<n;j++) {

                if ((arr[j] >> i & 1) == 1) {

                    countSet++;

                }

            }

            count += (countSet * (long) (n - countSet)) * 2; 

        }

        return count;

   
	}