Skip to content
We areTOP 1%

Longest Consecutive Sequence

MediumLeetCodeArrays & Hashing
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Put all values in a hash set and start counting only from numbers whose predecessor x - 1 is absent; each run is then walked once, giving O(n) overall.

More in Arrays & Hashing

Arrays & Hashing questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Contains DuplicateLeetCodeEasy Solve Contains Duplicate on LeetCode (opens in a new tab)
2Two SumLeetCodeEasy Solve Two Sum on LeetCode (opens in a new tab)
3ICPC BalloonsCodeforcesEasy 800Solve ICPC Balloons on Codeforces (opens in a new tab)
4Word GameCodeforcesEasy 800Solve Word Game on Codeforces (opens in a new tab)
5All DistinctCodeforcesEasy 800Solve All Distinct on Codeforces (opens in a new tab)
6Remove DuplicatesCodeforcesEasy 800Solve Remove Duplicates on Codeforces (opens in a new tab)
7Majority ElementLeetCodeEasy Solve Majority Element on LeetCode (opens in a new tab)
8Set MismatchLeetCodeEasy Solve Set Mismatch on LeetCode (opens in a new tab)
9FootballCodeforcesEasy 1000Solve Football on Codeforces (opens in a new tab)
10Two Teams ComposingCodeforcesEasy 1100Solve Two Teams Composing on Codeforces (opens in a new tab)
11A and B and Compilation ErrorsCodeforcesEasy 1100Solve A and B and Compilation Errors on Codeforces (opens in a new tab)
12Same DifferencesCodeforcesEasy 1200Solve Same Differences on Codeforces (opens in a new tab)
13Group AnagramsLeetCodeMedium Solve Group Anagrams on LeetCode (opens in a new tab)
14Majority Element IILeetCodeMedium Solve Majority Element II on LeetCode (opens in a new tab)
15Longest Consecutive SequenceLeetCodeMedium Solve Longest Consecutive Sequence on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account