Longest Consecutive Sequence

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Hashing — Pay Space, Buy Time

Replace nested loops with unordered_map / unordered_set lookups.

unordered_map<int,int> mp;
for (int i = 0; i < n; i++) {
    int need = target - nums[i];
    if (mp.count(need)) return {mp[need], i};
    mp[nums[i]] = i;
}
Hashing

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++17