Duplicate in On and O1 complexity

Given an array of n elements which contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space.

This was my code
But the problem is that if i have an element in an array which repeaats itself more than twice then its printing ,it more than once
eg … I/P => 1 2 2 3 4 (output - 2)
i/p=> 1 2 2 2 4( output 2 2) which is wrong

what should i do to solve this problem inO(N) and O(1) space ? If i have more an element appearing more than twice

hello @apoorv.chauhann

a) print any element only when a[current value -1 ] >0

check now->

My question is to print the duplicates element (not remove) like if it contain 1 1 2 2 2 4 then output should be [1 2]

then in ouput u cannot avoid repetetion of duplicates in o(1) space

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.