Lets say I have an array of integer elements, here I want to remove all the duplicate elements and print the remaining elements with out using any Java.util classes. I solved it using 2 pointers to scan and remove all the duplicates but which takes O(N^2). I just wanted to know is there any algorithm which can finish this task in O(N)?
Example:
Input Array: [1, 2, 3, 4, 5, 4, 3, 4, 6]
Expected Array: [1, 2, 5, 6]