Longest common subsequence solution.