Skip to interview prep
Apexed

69. Longest Consecutive Sequence

MediumHashing

Return the length of the longest run of consecutive integers that can be formed from the values in nums (order in the array does not matter). Aim for O(n).

Example 1

Input: nums = [100, 4, 200, 1, 3, 2]
Output: 4
Explanation: 1, 2, 3, 4

Constraints

  • 0 ≤ nums.length ≤ 10⁵

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Longest Consecutive Sequence — coding interview practice — Apexed