Loading...
Loading...
Loading...
From n integers (in any order, repeats allowed), find the length of the longest group of values that form consecutive numbers such as 5, 6, 7, 8. The order in the list does not matter.
Example
Input
6 100 4 200 1 3 2
Output
4
The values 1, 2, 3, 4.
Try the problem first. Open one hint at a time.
Put all values in a set so a lookup is fast.
Start counting only at a value whose predecessor is not in the set.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor