Longest consecutive subsequence search algorithm.