Move all x at the end


why output coming wrong???

Hi @Bansaljatin05
Basically there is a small error in your code.

string res= a.substr(0,i-1)+moveX(a.substr(i+1),0)+x;

Here your were doing a.substr(0,i-1) due to which you were missing (i-1)th character of your string so you should replace i-1 by i.

1 Like

After replacing there is run error in 2 nd test case

Yes this is because of your base case condition. It should be as follows :
if(a[i]==’\0’)
return a;