Loading...
You are given an array of integers nums. A run is a block of consecutive integers (values that each sit exactly one above the previous one, such as 7, 8, 9) where every value of the block appears somewhere in nums.
Return the length of the longest run that can be assembled from the values in nums.
Where the values sit in the array does not matter, only which values are present. A value that appears more than once still counts once toward a run's length. If nums is empty, return 0.
Input: nums = [100,4,200,1,3,2]
Output: 4
Explanation: The values 1, 2, 3, and 4 are all present, so they form a run of length 4. Neither 100 nor 200 has a neighbour to build on.
Input: nums = [0,3,7,2,5,8,4,6,0,1]
Output: 9
Explanation: Every value from 0 through 8 is present, so the run has length 9. The repeated 0 counts once.
Input: nums = [1,0,1,2]
Output: 3
Explanation: The run 0, 1, 2 has length 3; the second copy of 1 does not lengthen it.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.