883. Longest Consecutive Sequence: Scan Only Run Starts
Medium•
Let n = nums.length.
functionlongestConsecutive(nums){const values =newSet(nums)let best =0for(const value of values){if(values.has(value -1))continuelet end = value
while(values.has(end +1)) end++ best =Math.max(best, end - value +1)}return best
}
What are the expected time and auxiliary space complexities?