I need help with a JavaScript implementation for the following challenge.
Imagine we have a sorted array:
[1,2,5,9,10,12,20,21,22,23,24,26,27]
I want to find the length of the longest consecutive range that increments by 1 without duplicates.
In the provided example, we have the following ranges:
1,2
9,10
20,21,22,23,24 // longest range here
26,27
Therefore, the expected result for this example should be 5.
While I know how to solve this problem using a straightforward method, I am curious if there is a more efficient and concise algorithm available.