Loading...
Loading...
Loading...
A log holds event numbers in any order, possibly with repeats. A run is a group of numbers that follow each other, such as 4, 5, 6, 7.
Print the length of the longest run that can be made from the numbers in the log. Aim for O(n) time.
Example
Input
100 4 200 1 3 2
Output
4
The run 1, 2, 3, 4 has length 4.
Try the problem first. Open one hint at a time.
Put the numbers in a set. A number starts a run only when the number before it is not in the set.
From each start, count upward while the next number is in the set, and keep the largest count.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor