← Back
00:00

Longest Consecutive Sequence In An Array

Autodesk interview questions · Medium · Coding round · 7 tests

The integer array nums comes in no particular order. Find the size of the longest run of consecutive values (numbers that each differ by exactly one) that can be formed from its elements.

Your approach has to finish in O(n) time.

Examples

longestConsecutive([100, 4, 200, 1, 3, 2]) // 4
// 1, 2, 3 and 4 are all present, giving a run of four.
Idle