We have array a[ ]= {1, 2, 3, 4, 5, 6, 7, 8, 4, 10};
And we need to find a number which is duplicate in O(n) and Space complexity O(1)
And we need to find a number which is duplicate in O(n) and Space complexity O(1)
... A B C D E ...
–> next –> next –> next –>
<– prev <– prev <– prev <–
... A B C D E ...
<–> A⊕C <-> B⊕D <-> C⊕E <->
Input: A1[] = {2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8}
A2[] = {2, 1, 8, 3}
Output: A1[] = {2, 2, 1, 1, 8, 8, 3, 5, 6, 7, 9}
Ex: Input: 1 2 5 3 6 8 7
Output: 5 6 7 8
As given in Above example we need to find Longest Consecutive sequence in O(n)