CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsHashing

Longest Consecutive Sequence

Medium
LeetCode
8/8
MediumHashingLeetCode #128

Longest Consecutive Sequence

O(n): put all in a set; only start a streak when x-1 not in set.

Examples

Example 1

Input

6
100 4 200 1 3 2

Output

4
Example 2

Input

10
0 3 7 2 5 8 4 6 0 1

Output

9

Stuck? Take a nudge

C++17Autosaves