Sanket and strings 123

i am not getting the logic behind. please help with the logic

Hi Aastha, I’ve replied to this doubt in the other thread.