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.
@infinity_ @ktobah
Can you use hashes?
hashes need memory
non constant memory *
I don't think that you can do that with constant memory, i think you need an array.
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.....
you can't have arrays at all...
y?
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.
yea here temp is the only space we use nd we are given that array
If i understand, that would work if your array was sorted...
@infinity_ can u plz check this out? http://inder-gnu.blogspot.in/2010/11/find-duplicates-in-array-of-elements.html
ok, do this... I would do that in O(N) space if i had to, but this is ok i guess :P
can u xplain me what they did?
Join our real-time social learning platform and learn together with your friends!