Edit distance algorithm to find the longest common subsequence between two strings