You are not logged in. Please login at www.codechef.com to post your questions!

×

Find unique numbers from series without breaking order.

0
1

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.

asked 01 Apr '15, 15:19

vgg25's gravatar image

0★vgg25
133
accept rate: 0%


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

Complexity O(N)

link

answered 02 Apr '15, 00:07

fool_for_cs's gravatar image

4★fool_for_cs
462
accept rate: 33%

edited 02 Apr '15, 00:09

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

Time Complexity : No of elements.
Memory : No of unique elements.

link

answered 01 Apr '15, 15:30

siddhartha4444's gravatar image

4★siddhartha4444
1547
accept rate: 0%

edited 01 Apr '15, 15:30

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.

(01 Apr '15, 16:44) vgg250★

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.

link

answered 01 Apr '15, 16:19

vgg25's gravatar image

0★vgg25
133
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×34
×17
×9
×3

question asked: 01 Apr '15, 15:19

question was seen: 728 times

last updated: 02 Apr '15, 00:09