Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

Find duplicates in a array of elements.You are given an array of elements. some/all of them are duplicates. Find them in O(n) time and O(1) space. Property of inputs - Number are in the range of 1..n where n is the limit of the array.

OpenStudy (anonymous):

@infinity_ @ktobah

OpenStudy (barrycarter):

Can you use hashes?

OpenStudy (anonymous):

hashes need memory

OpenStudy (anonymous):

non constant memory *

OpenStudy (anonymous):

I don't think that you can do that with constant memory, i think you need an array.

OpenStudy (anonymous):

may be this will work how about traversing the array and if i get a number say 2 i copy the element in a temp and multiply 2 with the size of array nd place it in array[2] and move the value in temp to a[0] now if u get a number greater than n its a duplicate.....

OpenStudy (anonymous):

you can't have arrays at all...

OpenStudy (anonymous):

y?

OpenStudy (anonymous):

because you say constant space.Which means that the memory used does not depent on the input.When you have an array of N elements it is O(N) space.

OpenStudy (anonymous):

yea here temp is the only space we use nd we are given that array

OpenStudy (anonymous):

If i understand, that would work if your array was sorted...

OpenStudy (anonymous):

@infinity_ can u plz check this out? http://inder-gnu.blogspot.in/2010/11/find-duplicates-in-array-of-elements.html

OpenStudy (anonymous):

ok, do this... I would do that in O(N) space if i had to, but this is ok i guess :P

OpenStudy (anonymous):

can u xplain me what they did?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!