Please tell me why this code is giving run error in two test cases.Please correct it and tell my error

Link:https://ide.codingblocks.com/s/331565

hello @KetanPandey dry run your code for this test case
abbve
gbdea
expected ouput=be.
.
i hope you will find what is wrong
Happy Learning !!

no,my code is giving correct output ie be in this case and i am not even to point out any fault in my code.Please correct it,it will be a great help

@KetanPandey your code is giving error for the above test case.

In my codeblocks compiler,its not giving any error.If there is any error ,please tell me the error,or rectify it,i have gone through this code multiple time

Hey ,please rectify my code,i am not getting any error in it,or tell me my mistake in code,i am waiting since a day

hey @KetanPandey sorry i am replying late .
i have corrected your code and now it is working fine.


i hope i have cleared your doubt .
please mark this as resolved.
Happy Learning !!

Can you please tell me what was the mistake

You have changed this line β€œβ€β€œwhile(i!=0||j!=0)”"" to β€œβ€" while(i!=0 and j!=0) β€œβ€",but i am not getting why it is not working with or,as in dry run,it should work with or,Please explain,it would be a great help

Hey please answer!!!

hi @KetanPandey,
he change while(i!=0||j!=0)”"" to β€œβ€" while(i!=0 and j!=0) because when either of i or j becomes 0 then we have to stop the loop otherwise one of it will try to access str[-1] which gives the error.
Please let me know if there is any other doubt.

hello @KetanPandey sorry for late reply.
@Jun18ELX0057 have explained this in the right way .
if you have done or in the while condition this means that if either of them is true the while loop will run and in that case the loop will try to run for negative indexing in the false case .
but we dont have negative indexing that is the reason why it was showing error .
but when you are doing and in the while loop in this condition if either of the condition is false then it will not go inside the while loop .
this is the difference .
i hope your doubt is cleared now .
please mark this as resolved .
Happy Learning !!

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.