Solution for the longest increasing subsequence