It's actually similar to finding total hamming distance.
https://leetcode.com/problems/total-hamming-distance/#/description