Longest Common Subsequence algorithm implementation