values. Find the largest k such that, for some x, all of x, x + 1, …, x + k - 1 appear in the array (anywhere in it). Return k.
Repeated values count once. For an empty array the answer is 0.
Sorting gives O(n log n); aim for O(n).values=[40, 7, 5, 41, 6, 8, -1] → 4
5, 6, 7 and 8 are all present, an unbroken run of length 4; 40 and 41 give only 2.
values=[3, 3, 2, 2] → 2
Repeats do not extend a run: only 2 and 3 are there, so the answer is 2.
values=[] → 0
values=[40, 7, 5, 41, 6, 8, -1]
4
Run checks the first 3 tests in your browser. Submit checks all 129 tests on the server, hidden ones included.