Problem in Move all X at end problem


I am getting segmentation fault.

Implementation is not right, logic seems correct
do this

if(s[i]=='x')
	{
        int count =0; 
        int init = i;
		while(s[init]!=n)
		{
            if(s[init]=='x')count++;
			s[init]=s[init+1];
			init++;
		}
        s[n-1]='x'; 
		s[n]='\0';
        if(count==(n-i))return abc(s,n) 
		return abc(str,i);

	}

Coding Blocks IDE
Made changes according o your code still getting segmentation fault

Check now ->


Passing all test cases.

Can you please expain why have you done return abc(s,n); whereas the function abc is void.

this is done when we have placed all x at the end of the array, so i have sent n in place of i so that in base condition when i is equal to n, we return cause our work is done. Dry run it, you will understand the intuition . If find it difficult let me know will help accordingly.

I am not asking that I am asking about using return abc(s,n); when the function abc is void, shouldn’t it be abc(s,n);

You can do that also, it’s same.

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.