Jan 302013
 

Write code to calculate hamming distance between two strings.

Hamming distance between two strings of equal length is equal to the total number of positions at which corresponding characters in the two strings are different.

   String-1       String-2     Hamming distance
 ------------   ------------   ----------------
  TONED           ROSES               3
  KAMAL           RAWAT               3
  203             233                 1
  RITAM           BHARA               5
  OK              TATA                infinite (not equal sized)

If size of two strings is not same then the hamming distance between them is infinite.
Continue reading »