113. Longest Consecutive Sequence
Challenge1000 ms256 MBSolved by 0%
Print the length of the longest run of consecutive integers that can be formed from the values in the array, in any order.
For [100, 4, 200, 1, 3, 2] the run is 1, 2, 3, 4, so the answer is 4.
Duplicates do not extend a run.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print one integer, the length of the longest run of consecutive values, in any order.
Input6
100 4 200 1 3 2
Output4
Noteis the worked example from the statement
Input4
10 20 30 40
Output1
Notehas no two consecutive values, so the longest run is a single element
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.