I am unable to get the logic behind the code