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.
numbers: number[]
: An array of integersInput: numbers = [1,-1,-1,-4,-5]Output: 2Explanation: The longest consecutive subsequences are -1, 1 and -5, -4, both with a length of 2
Input: numbers = [5,1,-4]Output: 1Explanation: 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: 4Explanation: The longest consecutive subsequence is 8, 9, 10, 11, with a length of 4 and duplicates are ignored.
numbers.length
<= 100,000numbers[i]
<= 1,000,000,000Given 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.
numbers: number[]
: An array of integersInput: numbers = [1,-1,-1,-4,-5]Output: 2Explanation: The longest consecutive subsequences are -1, 1 and -5, -4, both with a length of 2
Input: numbers = [5,1,-4]Output: 1Explanation: 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: 4Explanation: The longest consecutive subsequence is 8, 9, 10, 11, with a length of 4 and duplicates are ignored.
numbers.length
<= 100,000numbers[i]
<= 1,000,000,000console.log()
aparecerão aqui.