Move x at the end run time error

I am trying to copy all x encountered at the n-1 th pos and passing the n-1 again to recursive call.
whne j==n out[original length of inp string]=’\0’ and printing the string.But the code is going into runtime error.


i have remove your runtime error but there is problem with your approach
when you are coping data at nth index then at end there are some vaccant space left so it give no correct ans
see output of this code to understand better

In my code I am adding x from the last element and reducing the last element in the subsequent calls.

Passed all test cases …Thanks