utility for finding lcs