Levenshtein and Hamming distance computation