Вам предоставляется массив чисел, и они являются несортированными/случайными. Вы должны найти самую длинную последовательность последовательных чисел в массиве. Обратите внимание, что последовательность не обязательно должна быть упорядочена в массиве. Вот пример:
Вход:
A[] = {10,21,45,22,7,2,67,19,13,45,12,11,18,16,17,100,201,20,101}
Выход:
{16,17,18,19,20,21,22}
Решение должно иметь сложность O (n).
Мне сказали, что решение включает использование хеш-таблицы, и я столкнулся с несколькими реализациями, которые использовали 2 хэш-таблицы. Нельзя сортировать и решать это, потому что для сортировки потребуется O (nlgn), что не является желаемым.