Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Longest Consecutive Sequence (medium)

Problem Statement

Given an unsorted array of integers, find the length of the longest consecutive sequence of numbers in it. A consecutive sequence means the numbers in the sequence are contiguous without any gaps. For instance, 1, 2, 3, 4 is a consecutive sequence, but 1, 3, 4, 5 is not.

Examples

    • Input: [10, 11, 14, 12, 13]
    • Output: 5
    • Justification: The entire array forms a consecutive sequence from 10 to 14.
    • Input: [3, 6, 4, 100, 101, 102]
    • Output: 3

.....

.....

.....

Like the course? Get enrolled and start learning!