solution to find LCS