Arrays & Hashing pattern
Longest Consecutive Sequence
Given an unsorted array of integers, return the length of the longest sequence of consecutive integers (in any order). Solve it in O(n) time. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 128
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Arrays & HashingLeetCode 128
Medium
From the first idea to the best one
- 01 Brute force · sort O(n log n)O(n) space
- 02 Optimized · set + sequence starts O(n)O(n) space
What you will learn
- How to read Longest Consecutive Sequence and spot the arrays & hashing pattern in it
- Brute force · sort: O(n log n) time, O(n) space
- Optimized · set + sequence starts: O(n) time, O(n) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Arrays & Hashing
See Longest Consecutive Sequence run, step by step
Sign in and this page opens on the animation, with all 13 Arrays & Hashing problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.