Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
Brute Force
Sorting
Hash Table based look up
def longest_consecutive_sequence(nums: List[int]) -> int: entries = set(nums) best = 0 for num in nums: if num-1 not in entries: next_num, seq_len = num+1, 1 while next_num in entries: next_num += 1 seq_len += 1 best = max(best, seq_len) return best