Dsa
Two Pointers
Hard
Longest Sequence of Consecutive Numbers
Given an unsorted array of integers, find the length of the longest sequence of consecutive integers. The function should return the length of the longest sequence found. An empty array should return 0. Use the two pointers strategy effectively in your solution. The function should read from standard input and print the result.
Example:
Input:
7
100 4 200 1 3 2 5
Output:
5
Explanation: The longest consecutive sequence is [1, 2, 3, 4, 5].
Key concepts
two_pointerssetsorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now