Longest Consecutive Run
Talk it through out loud with your AI coach.
The problem
- medium
- Pro
Given an unsorted list of integers, find the length of the longest run of consecutive values, such as four, five, six and seven, which may appear in any order in the list. Explain how to do it in linear time.
What a strong answer covers
- A sorting-based answer as a baseline, and its cost.
- A structure that answers membership questions quickly.
- How to avoid recounting the same run from many starting points.
- Why the whole approach stays linear.
Common mistake: Walking upward from every number, which quietly turns the solution quadratic.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud