Print dupliactes in o(n) time and o(1) space

https://practice.geeksforgeeks.org/problems/find-duplicates-in-an-array/1
for this question my code isn’t working when dupliactes consists of zero
can u please expalin a better algorithm for this.


this is my code

Hey @Sagarjha07
simply iterate over the array and maintain the frequency of every element using map.
then iterate over map and if freq of that element is > 1 print it.
if no one has freq > 1 print -1

But we have to do it in o(1) space

ok then just check for zero in your code separately.
when you are traversing check if arr[i]==0 increment a variable cnt and when cnt becomes 2
print 0

Can u please send me the complete code?

here see this as numbers are between 0 and n-1 this can be implemented simply-

@Sagarjha07 i hope your doubt is cleared don’t forget to mark it resolved in my doubts section :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.