Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Consecutive Trail

Learn
Play
Prove
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

  1. 1Recognize when Hash-set sequence starts matches the clues
  2. 2Keep this true after every move: each consecutive run is expanded exactly once from its smallest value
  3. 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 execution
1 of 7

Build a set so predecessor and successor checks are constant time.

1values = set(nums)
2for value in values
3skip if value - 1 exists
4length = 1
5extend while value + length exists
6best = max(best, length)
7return best
values = {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?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead