Last Forever Hackerearth(MANACHAR)

How to solve this question?

Hello @Bhawna please wait let me go thorugh the question:
till then you can go with this correct code for it :


Happy Learning!!

Ok…But I didn’t get any clarity just by seeing code

@Bhawna if you will dry run you will able to understand in the better manner.
Happy Learning!!

Just tell me logic ,I will write myself ,I am not getting

Sir help…

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.

No my doubt is not clear help!