solution for all pairs hamming distance