Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort the array and try using dynamic programming.
Let <code>dp[i]</code> be the length of the longest consecutive elements ending at element at index <code>i</code> in the sorted array.