| Topic | Difficulty | Companies |
|---|---|---|
| Hash Table | HARD | Amazon Google |
Given an unsorted integer array arr consisting of n integers, write a program to find the length of the longest consecutive sequence of integers in the array.
Problem Note
O(n).Example 1
Input: arr[] = [1, 9, 3, 10, 4, 20, 2]
Output: 4
Explanation: The longest consecutive sequence in the above input array is [1, 2, 3, 4]. Hence, its length is 4.
Example 2
Input: arr[] = [20, 28, 12, 18, 23, 19]
Output: 3
Explanation: The longest consecutive sequence in the above input array is [18, 19, 20]. Hence, its length is 3.