What's the use of a[prev]=a[current]?

Here if both aren’t equal then we are doing prev++ and what’s the use of a[prev]=a[current]?

Hi,

After prev++ we need to insert the another different character next to the previous one. That is why, a[prev]=a[current] is done.

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.