Advertisement
andreahmed

Untitled

Dec 18th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
  2.  
  3. Now your job is to find the total Hamming distance between all pairs of the given numbers.
  4.  
  5. Example:
  6. Input: 4, 14, 2
  7.  
  8. Output: 6
  9.  
  10. Explanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just
  11. showing the four bits relevant in this case). So the answer will be:
  12. HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.
  13. Note:
  14. Elements of the given array are in the range of 0 to 10^9
  15. Length of the array will not exceed 10^4.
  16. Discuss
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement