Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Start only where a sequence begins: The Consecutive Trail.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Hash-set sequence starts matches the clues
- 2Keep this true after every move: each consecutive run is expanded exactly once from its smallest value
- 3Reach the result within O(n) expected
Rules and pressure
- Target cost: O(n) expected
- State rule: each consecutive run is expanded exactly once from its smallest value
Lesson 1 of 3
Live algorithm trace
Hash-set sequence starts
Complete execution1 of 7
Build a set so predecessor and successor checks are constant time.
1
values = set(nums)2
for value in values3
skip if value - 1 exists4
length = 15
extend while value + length exists6
best = max(best, length)7
return bestvalues = {1,2,3,4,100,200}best = 0
Truth to preserve / Cost target
Truth to preserve
each consecutive run is expanded exactly once from its smallest value
Cost target
O(n) expected
A set makes membership constant time. Only values with no predecessor may start a run, preventing repeated scans through the middle of the same sequence.
Your call · What should guide every step of this algorithm?