linear time detection of longest consecutive sequence