Find unique numbers from series without breaking order.

Hi,

I’m new to codechef. Please assist me if its repeative post.

I’m C++/STL developer and looking for:

finding unique numbers from series on integer number wihtout changing its order.
e.g:
i/p: 10,4,3,6,1,0,4,4,4,10,5,9,0,6,15,…
o/p(expected result): 10,4,3,6,1,0,5,9,15,…

Constraint:

  • time complexity should not be worst(N^2). Need to solve it in less time.
  • memory is adequate.
  • appricieate, if you can explain about STL containers or algorithm I must use to resolve this problem.

You can add all numbers in a hashset and then print the set

Time Complexity : No of elements.

Memory : No of unique elements.

Thnx sidhartha4444 for your prompt reply but unorder_set will break series ordering.

with unorder_set o/p : 0 1 3 15 4 5 6 9 10.

This is incorrect.

Thnx sidhartha4444 for your prompt reply but unorder_set will break series ordering.

with unorder_set o/p : 0 1 3 15 4 5 6 9 10.

This is incorrect.

NOTE: I presuming unorder_set is equivalent to hash_set.

for : i 1 to N
if(element does not exist in HashSet)
add to hash set and print

Complexity O(N)