As reported: Expedia SDE-2 round 1 DSA (Bangalore, 2025): Longest Consecutive Sequence with a HashSet in
O(n), then Reorder Linked List.
Given an unsorted array of integers nums, return the length of the longest sequence of consecutive values that all appear in it, in O(n) time.
This is LeetCode 128 — Longest Consecutive Sequence.
Example
[100,4,200,1,3,2] -> 4
[0,3,7,2,5,8,4,6,0,1] -> 9
Constraints: 0 ≤ nums.length ≤ 10^5; -10^9 ≤ nums[i] ≤ 10^9.
Code runner format: one line with nums. Implement longestConsecutive(nums); the harness prints the length.