FunctionRacerProblemsRace

Longest Consecutive Sequence

MediumHash mapsPython, JavaScript, TypeScript, Java, C++

Return the length of the longest group of numbers from nums that form consecutive integers, like 5, 6, 7, 8. The numbers can sit anywhere in the list and in any order. Repeated values count once.

An empty list gives 0.

Example 1

nums [100,4,200,1,3,2]
returns 4

1, 2, 3, 4 is the longest run, so 4.

Example 2

nums [7,7,7]
returns 1

Repeats count once, so the length is 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems