Medium · Arrays & hashing

Longest Consecutive Sequence

You are given a list of whole numbers in no particular order. Return the length of the longest run of consecutive values, such as 1, 2, 3, 4, wherever they sit in the list.

  • The list can be empty, and the answer is then 0.
  • Repeated values count once.
  • Aim for one pass over the numbers, without sorting.
nums = [100, 4, 200, 1, 3, 2]

→ 4   (1, 2, 3, 4)
Record your take

No one has solved it yet.