Longest increasing sequence implementation