Will you please look into my code whats wrong in this ,, i am not passing all the test cases

link of my code ishttps://ide.codingblocks.com/s/340790
link of the questionhttps://practice.geeksforgeeks.org/problems/remove-b-and-ac-from-a-given-string/0 please check it once and update my error, the error is somewhere around in if loop where i am checking that the current element is equal to a and next is c

Hey @shashank_sabharwal
Erase function will delete characters from string which changes length of the string and affect the loop running so next character will be at current i and not at next i
Here did the req changes https://ide.codingblocks.com/s/340808

why you write i=i-1 in both the if conditions, how erase function effects my for loop , please explain so in future no need to ask you again, please explain with the example , please i want to know which character come and at which position, after erase function

so assume u had “bbx”
for i=0 it finds b and erase it so string becomes “bx”
then at i=1 it checks from x and b is missed
so hence we did i=-1 whenever we erase so it checks from current index only

sir the is still not able to pass all the test cases please check it i already posted the question link

okkk itpasses all the test cases now

recheck I already tried

but sir i have still doubt in this please explain with 2 examples

how my i jump to the posotion which is i+1, in every case , in the second if case i delete 2 elements friom the string but you write i = i-1 in the second case also how??

Say we have
bacxyiac
i=0 we have b we delete it ,string becomes acxyiac
and i increments to 1 so now it will check from c
i=2 x
i=3 y
i=4 i
i=5 we get ac so we we erase it so string becomes acxyi and we stop since str.length() =5>i
Here see whenever we erase we are missing few characters in front of it because string is shifted towards left

So to avoid this we do i-=1 so when loop increments i++ then i is not changes and remains at its current condition

Do dry run yourself to understand better :slight_smile:

please wait ,see you give me the example bacxyiac see first i=0; i found b so b is erased now my string is accyiac and now i=1 which is c here in new string so we again decrement i by 1, so now iwill check from a and according to my second if condition i==a and i+1==c it will erase a and c from this string ac cyiac now my i becomes 2 which is( i )in this but you still write i = i-1 in the second if why ??? this is my doubt pls explain sir, not ale to understand

I becomes 1 not 2 because u

did this

Just print your string in every iteration in your code

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.