Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use a set for O(1) lookups and only start counting at sequence starts.

Approach

Insert all numbers into a set. For each number x, if x-1 isn’t in the set, treat x as the start and count upward until the chain ends.

Why it works

Each number is visited in a counting loop at most once across all starts, giving linear time.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Use a set for O(1) lookups and only start counting at sequence starts.

Approach

Insert all numbers into a set. For each number x, if x-1 isn’t in the set, treat x as the start and count upward until the chain ends.

Why it works

Each number is visited in a counting loop at most once across all starts, giving linear time.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)