Help needed...

Please help me in finding the error in my code.
http://www.codechef.com/viewsolution/4046024

Thanks!

You have to check whether the element has been once replaced or not. So keep a visited array[] where you have to replace the element only if visited[k] if not visited. Check this code. Hope you got the mistake. In my programme the visited[] is of the name check[] here is the code click here