The longest run of consecutive integers in an unsorted list, in O(n): from re-walking every run, to sorting, to a hash set that only starts counting at the beginning of each run. Then streaming inserts with union-find, small value ranges, and activity streaks from event logs.
about 10 min 5 Python examples 2 quick checks
Problem. Given an unsorted list of integers, return the length of the longest run of consecutive values
(like 1, 2, 3, 4). The values can appear in any order. Aim for O(n) time.
ML context. "The longest streak" from unordered data: the most consecutive days a user was active (from an event
log that isn't sorted), the longest run of consecutive frame ids with a detection, or the longest stretch of ids that
are present in a dataset (to find gaps). Sorting works; the lesson is how hashing removes the sort.
1. Step 1: Clarify
That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson
Unlock "Longest Consecutive Sequence"
The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.
Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied