Brute force method to find LCS