Longest Consecutive Number Sequence

Languages

Given an unsorted array of integers numbers, determine the length of the longest subsequence where the integers appear consecutively, meaning the numbers follow one another without any gaps.

Input

  • numbers: number[]: An array of integers

Notes

  • Solution should have a time complexity of O(n)

Examples

Input: numbers = [1,-1,-1,-4,-5]
Output: 2
Explanation: The longest consecutive subsequences are -1, 1 and -5, -4, both with a length of 2
Input: numbers = [5,1,-4]
Output: 1
Explanation: No consecutive numbers exist, so the longest subsequence is any single number, giving a length of 1
Input: numbers = [1,-1,0,8,11,10,9,9]
Output: 4
Explanation: The longest consecutive subsequence is 8, 9, 10, 11, with a length of 4 and duplicates are ignored.

Constraints

  • 0 <= numbers.length <= 100,000
  • -1,000,000,000 <= numbers[i] <= 1,000,000,000