Loading...
Loading...
Loading...
The store keeps a list of order numbers, in any order and possibly with repeats. A run is a group of numbers that follow one another, such as 7, 8, 9. Find the length of the longest run.
Example
Input
6 100 4 200 1 3 2
Output
4
1, 2, 3, 4 is a run of length 4.
Try the problem first. Open one hint at a time.
Put all numbers in a HashSet. A run can only start at a number whose previous number is not in the set.
From each start, count up while contains(x + 1) is true.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor