Ex: Input: 1 2 5 3 6 8 7 Output: 5 6 7 8As given in Above example we need to find Longest Consecutive sequence in O(n)
I have implemented in O(n) considering by creating hash of data type bool.
Ex: Input: 1 2 5 3 6 8 7 Output: 5 6 7 8As given in Above example we need to find Longest Consecutive sequence in O(n)
1) Keep a Min & Max Heap of K size 2) Store first K elements in them. 3) If a new element comes with smaller or larger than root then reorder heap.
BinarySearch(A[0..N-1], value)
{
low = 0
high = N - 1
while (low <= high) {
mid = low + ((high - low) / 2)