contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
0 -> 31
.noOfZeroes
and noOfOnes
.noOfZeroes * noOfOnes
ones will be there if XOR is taken.class Solution {
public:
int totalHammingDistance(vector<int>& nums) {
int ans = 0;
for (int i = 0; i < 32; i++) {
int mask = (1 << i);
int countZero = 0;
int countOne = 0;
for (const auto& num: nums)
mask & num ? countOne ++ : countZero ++;
ans += (countOne * countZero);
}
return ans;
}
};